Vue2.5.x --- 获取元素文本内容

比方需要拿到这个H2标签的文本内容

<h2>Ecosystem</h2>

那么先给这个元素加个触发事件

<h2 v-on:click="greet">Ecosystem</h2>

然后在methods中添加事件函数

methods: {
   greet: function (event) {
     console.log(event.target.innerText);//打印得到了Ecosystem
   }
 }

猜你喜欢

转载自blog.csdn.net/sinat_19327991/article/details/80513366