我正在尝试从另一个计算属性获取计算属性,如下所示:var instance = new Vue({ el: "#instance", data: { aha: "" }, computed: { len: function(){ return this.aha.length; }, plus : function(){ return this.len + 2; } }});这不起作用。我得到NaN在我的模板,当我试图显示plus。有没有办法使这项工作?这个问题的答案对我不起作用。
2 回答
![?](http://img1.sycdn.imooc.com/533e52b90001456f02000200-100-100.jpg)
慕森卡
TA贡献1806条经验 获得超8个赞
您正在尝试访问lengthtype 字段number。
this.len是数字,所以this.len.length是未定义的。你只需要使用this.len:
var instance = new Vue({
el: "#instance",
data: {
aha: ""
},
computed: {
len: function(){
return this.aha.length;
},
plus : function(){
return this.len+ 2;
}
}
});
添加回答
举报
0/150
提交
取消