Vue获取自定义标签的数据

1.参数传递。

 

如下代码:

 

 

<button @click="say('Hi')">say hi</button>

 

methods: {

 

    say(message){

 

        console.log(message)

 

    }

 

}

 

2.通过e.target.dataset.***  或者 e.target.getAttribute('data-***')来获取。

 

<button @click="sayBye($event)" data-msg="Bye">say bye</button>

 

methods: {

 

    sayBye(e){

 

        //let msg=e.target.getAttribute('data-msg');

 

        let msg=e.target.dataset.msg;

 

        console.log(msg)

 

    }}

 

3.通过$refs获取。

 

<button @click="sayHello()" data-msg="Hello" ref="dataMsg">say hello</button>

 

methods: {

 

    sayHello(){

 

        let msg=this.$refs.dataMsg.dataset.msg;

 

        console.log(msg)

 

    }

 

}

 

posted on 2021-11-04 14:25  年夜饭  阅读(467)  评论(0)    收藏  举报

导航