vue中怎么获取dom元素中的内容

时间:2022-12-06 01:48

vue中怎么获取dom元素中的内容

vue中获取dom元素中内容的方法:

vue中是通过给标签加ref属性,然后在js中利用ref去引用它,从而操作该dom元素。

示例:

<template>

<div>

<divid="box"ref="mybox">

DEMO

</div>

</div>

</template>

<script>

exportdefault{

data(){

return{

}

},

mounted(){

this.init();

},

methods:{

init(){

constself=this;

this.$refs.mybox.style.color='red';

setTimeout(()=>{

self.$refs.mybox.style.color='blue';

},2000)

}

}

}

</script>

<stylescoped>

#box{

width:100px;

height:100px;

line-height:100px;

font-size:20px;

text-align:center;

border:1pxsolidblack;

margin:50px;

color:yellow;

}

</style>

标签:
随便看看
本类推荐
本类排行
热门标签

我国国家通讯社行不行啊细狗新年贺词祝福语2023年祝福语新年新年贺词新年贺词祝福语居家抗病毒小药箱除夕高速免费吗2022年除夕高速免费吗春联春联句子大全春联句子大全七字年夜饭十二道菜年夜饭十二道菜单年夜饭吃什么年夜饭吃什么菜吃年夜饭的寓意年夜饭黑芝麻菊花茶晒菊花茶腌腊肉送妈妈生日礼物汉白玉送闺蜜水钻送女人礼物爸爸生日送礼物送老公