我在vue中使用CreateElement/render将父对象的props 向下传递到已创建的子对象时遇到问题.然后看.
这是我的父组件
Vue.component('my-drawing', MyDrawing)
new Vue({
el: '#drawing',
mounted() {
Bus.$on('emitColorSelection', (emitString) => {
console.log("inside socket.js/my-drawing and emitString is ", emitString);
this.useColor = emitString;
console.log('inside socket.js/my-drawing and this.useColor after set is ', this.useColor);
})
},
data() {
return {
channel2: null,
canvases: [],
useColor: 'rgba(255, 0, 0, 1)'
}
},
render(createElement) {
return createElement(MyDrawing, {
props: {
useThisColor: this.useColor
}
})
}
});
你们可以看到,我取一些总线的emit值,然后把它传递给useColor.然后我想将这个值作为useThisColor传递给我的渲染函数.
子元素来了.
<template>
//my template stuff
</template>
<script>
//stuff
watch: {
useThisColor (n, o) {
console.log("useThisColor watch, ", n, o) // n is the new value, o is the old value.
}
}
//stuff continues
所以这个手表标签不会输出.我也try 过将props 放在模板中而不产生任何效果,并try 将其输出到Updated:
标签上.我还try 使用引号在父对象中设置props .到目前为止,一切都不管用,我有点困惑.如果有人有任何 idea ,请告诉我.