刚才在群里问这个问题有人说可以重名,自己做了个测试发现报这样的错误:
<div id="chongming">
{{testname}}
<button v-on:click='dianji'>点击</button>
</div>
new Vue({
el:'#chongming',
data:{
testname:'这是转换信息你知道么?'
},
methods:{
testname:function(){
console.log(123);
},
dianji:function(){
this.testname = this.testname.split('').reverse().join('');
this.testname();
}
}
});
所以特来问问大家的看法,现在我已经明白了,不能重名,谢谢大家。
不可以。
Vue会把methods和data的东西,全部代理到Vue生成的对象中。
因此this. testname会被覆盖。