用element框架写click事件:
<el-button :ref="testRef" type="text" @click="testbtn">111</el-button>
data() {
return {
testRef:{},
};
},
methods: {
testbtn() {
this.$refs.testRef.innerHTML = '222'
};
}
点击报错,找不到指定innerHTML
询问前辈,原因是这个直接写入用的就是原生方法获取dom,可能跟el-button事件机制冲突了,框架基本从不用inner。
正确写法:
<el-button :ref="testRef" type="text" @click="testbtn">{{testMsg}}</el-button>
data() {
return {
testRef:{},
testMsg: "111",
};
},
methods: {
let that = this;
that.testRef = "222";
}
如果要用innerHTML方法,首先直接用<div>不用<el->,且:ref改为ref
<div ref="testRef" type="text" @click="testbtn">111</div>
data() {
return {
testRef:{},
};
},
methods: {
testbtn() {
this.$refs.testRef.innerHTML = '222'//this.refs.获取制定DOM.输出值:原始值
};
}