Vue2.5.x --- 获取元素文本内容
比方需要拿到这个H2标签的文本内容<h2>Ecosystem</h2>那么先给这个元素加个触发事件<h2 v-on:click="greet">Ecosystem</h2>然后在metho
·
比方需要拿到这个H2标签的文本内容
<h2>Ecosystem</h2>
那么先给这个元素加个触发事件
<h2 v-on:click="greet">Ecosystem</h2>
然后在methods中添加事件函数
methods: {
greet: function (event) {
console.log(event.target.innerText);//打印得到了Ecosystem
}
}
更多推荐
已为社区贡献2条内容
所有评论(0)