我在使用vue.js中的CreateElement / render然后观看它时,通过已创建的子项向父母传递道具时遇到问题。
这是我的父组件
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
所以这个表标签没有输出。我还尝试将道具放在模板中无效,并试图将其输出到Updated:
标签上。我还尝试使用引号在父级中设置道具。到目前为止没有任何工作,我有点困惑。如果有人有任何想法,请告诉我。