小编Tom*_*ang的帖子

如何在 html <object> 标签中嵌入 SVG 从 Cross Origin url 说 (s3_url/image.svg)

我浏览了我可以在互联网、MDN、W3C 等上找到的所有可能的资源,但我找不到任何关于 cors 的文档。

我正在尝试在 HTML 中嵌入一个 SVG 。它在同源 URL 中工作正常

<object id="obj1" data="same_origin_url/image.svg"></object>
Run Code Online (Sandbox Code Playgroud)

使用 cross_origin_url 时,无法嵌入 SVG。

<object id="obj2" data="cross_origin_url/image.svg"></object>
Run Code Online (Sandbox Code Playgroud)

在第一种情况下,我可以使用以下代码访问 SVG 并在 SVG 上执行所需的操作(如更改颜色)。

document.getElementById('obj1').contentDocument.getElementByTagName('svg')
Run Code Online (Sandbox Code Playgroud)

而在第二种情况下,它返回抛出错误,因为 obj2 的 contentDocument 返回 null。

document.getElementById('obj2').contentDocument.getElementByTagName('svg')
Run Code Online (Sandbox Code Playgroud)

html javascript svg cors

8
推荐指数
1
解决办法
304
查看次数

v-如果未在计算属性上触发

我有一个vuex商店.在vuex商店中改变国家偏好.我想重新渲染DOM.我希望每次vuex商店中的状态首选项发生变化时都会调用checkValue方法.

的index.html

<div id="app">
    <my-component></my-component>
    <my-other-component></my-other-component>
</div>
Run Code Online (Sandbox Code Playgroud)

vue已初始化,并且此处也导入了商店

my_component.js

Vue.component('my-component',require('./MyComponent.vue'));
import store from "./store.js"
Vue.component('my-other-component',require('./MyOtherComponent.vue'));
import store from "./store.js"

new Vue({
    el : "#app",
    data : {},
    store,
    method : {},
})
Run Code Online (Sandbox Code Playgroud)

在存储中更改状态首选项时需要更改DOM的组件

MyComponent.vue

<template>
    <div v-for="object in objects" v-if="checkValue(object)">
        <p>hello</p>
    </div>
</template>


<script>
    methods : {
        checkValue : function(object) {
            if(this.preference) {
                // perform some logic on preference
                // logic results true or false
                // return the result
            }
        }
    },

    computed : {
        preference : function() {
            return …
Run Code Online (Sandbox Code Playgroud)

vue.js vuex

7
推荐指数
1
解决办法
1万
查看次数

移除 vue 中的事件监听器

我需要删除事件侦听器。我正在从事件侦听器中执行的函数调用某些方法,因此我需要使用 es6 语法。我不能使用命名函数。如何删除事件侦听器

methods :
    initCanvas : function(x, y, width, height) {
        //do something
    },
    some_method : function() {
        let svgObjectEl = // some logic will give the object elemenet embedding the svg
        svgObjectEl.addEventListener('load', () => {
            //let x,y,width, height has some value
            // some code here
            this.initCanvas(x, y, width, height);         
        });   
        svgObjectEl.removeEventListener('load', ??);
}
Run Code Online (Sandbox Code Playgroud)

javascript addeventlistener ecmascript-6 vue.js

6
推荐指数
1
解决办法
1万
查看次数

TypeScript 中 createReadStream 的类型应该是什么?

我正在尝试使用打字稿。createReadStream 的类型应该是什么?我从github上的DefineTyped 链接fs.d.ts的文件中找到了以下类型声明

更新

我想做的是从前端上传文件。在后端(基本上是节点),我收到一个文件对象。在破坏文件对象时,我得到以下信息。

const { createReadStream, filename, mimetype, encoding } = await file;
Run Code Online (Sandbox Code Playgroud)

有什么办法,我可以使用这种类型吗?

更新的问题

现在,我应该如何在下面给出的函数的函数参数中添加我收到的 文件对象的类型?

export const processUpload = async (file, DestinationDir) {

}
Run Code Online (Sandbox Code Playgroud)

官方node/fs.d.ts文件中找到的类型

function createReadStream(path: PathLike, options?: string | {
        flags?: string;
        encoding?: string;
        fd?: number;
        mode?: number;
        autoClose?: boolean;
        /**
         * @default false
         */
        emitClose?: boolean;
        start?: number;
        end?: number;
        highWaterMark?: number; …
Run Code Online (Sandbox Code Playgroud)

fs node.js typescript

6
推荐指数
1
解决办法
8981
查看次数