我正在尝试创建一个小型数据编辑器。单击处理程序将在父类别中添加子项目,如下所示:
methods: {
addBlank: function(parentKey){
var obj = {}
obj.id = Math.floor((Math.random() * 99999) + 1)
obj.name = "New Item"
obj.data1 = 9
obj.data2 = 9
obj.data3 = 9
this.categories[0].children.push(obj)
console.log("New ref is:",obj.id)
console.log(this.$refs) // new $ref is available
console.log("I can't select it",this.$refs[obj.id]) //returns undefined
console.log("But I can select others",this.$refs['4214234']) //this is ok
}
}
Run Code Online (Sandbox Code Playgroud)
Codepen 示例: https: //codepen.io/Kay_Wolfe/pen/xJEVRW
当它存在时,为什么this.$refs[obj.id]回报不足?