javascript – 尝试在Vue.js中通过渲染传递道具并观察它们

前端之家收集整理的这篇文章主要介绍了javascript – 尝试在Vue.js中通过渲染传递道具并观察它们前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在使用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,1)'
    }
  },render(createElement) {
    return createElement(MyDrawing,{
      props: {
        useThisColor: this.useColor
      }
    })
  }
});

所以你可以看到这里是我取一些总线的发射值然后我把它传递给useColor.我想将此值作为useThisColor传递给我的渲染函数.

这就是孩子.

所以这个表标签输出.我也尝试将模板中的道具放在一起,以及尝试在Updated:标签输出它.我还尝试使用引号在父级中设置道具.到目前为止没有任何工作,我有点困惑.如果有人有任何想法,请告诉我.

最佳答案
我希望这里的问题是你没有在MyDrawing组件上定义属性useThisColor.

这是一个example.

原文链接:https://www.f2er.com/js/429170.html

猜你在找的JavaScript相关文章