【发布时间】:2019-02-05 14:23:32
【问题描述】:
所以我有一个演示应用程序,其中我通过根中的计算属性生成一个随机数,并使用道具将该计算值传递给子组件。
每当我在点击时生成随机值时,我都无法找出更新子组件中值的正确方法。
此外,jquery dom 选择很奇怪,它有时会给我未定义的信息,有时它可以工作并突出显示单元格。
这是我的codepen
Vue.component('grid',{
template:'#grid',
props:['randval'],
data:function(){
return{
title:"items",
items:["A","B","C","D","E","F","G","H","I"]
}
},
computed:{
getValues:function(){
$('.cells').removeClass('highlight');
$('#cell_'+this.randval).addClass('highlight');
console.log($('#cell_').text(), this.$refs.cell_1); // for example this return undefined sometime and works other times
return this.randval;
}
}
});
let app = new Vue({
el:"#app",
data:{
val:0
},
methods:{
randFun:function(){
this.val = parseInt(Math.random()*10);
}
},
computed:{
watchVal:function(){
return (this.val<9)?this.val:0;
}
}
});
【问题讨论】:
标签: jquery dom vue.js components