Vue element button

<el-button type="primary" @click="btn1" :data-value="btnarray.btn1" native-type="button"></el-button>
data() {
      return {
        btnarray:{
            btn1:"",
            btn2:""
        }
      }
    },

if you want to assign a value to the button, get the value of the button when you click it. But why do you get this value sometimes and undefined

sometimes?

sometimes the result is this:

clipboard.png

:

clipboard.png

Feb.12,2022

using vue is not recommended to operate dom, you want to click to get the value of the button, as far as possible to use the method of passing parameters.

<el-button type="primary" @click="btn1(btnarray.btn1)" :data-value="btnarray.btn1" native-type="button"></el-button>
export default {
    data () {
        return {
            ...
        }
    },
    methods: {
        btn1 (value) {
            console.log(value) //
        }
    }
}

do not operate dom, with vue. Do not use the thinking of the jquery era. You can add a variable directly to data

.
Menu