Vue button text changes dynamically

1. Event
2. Get element
3. Function
---------------------- Look carefully and have what you want!

<template>
    <!-- $event是获取当前元素属性 -->
    <!-- ref相当于id -->
    <el-button ref='btn1'  @click="getname($event)">你好,我是黄晓明</el-button>
</template>
<script>
export default {
  name: "flowDetail",
  data() {
    return {
        stuname:'我是朱晓明'
    };
  },
  components: {
    
  },
  methods: {
      getname(val){
          //console.log(val.target.innerText )
          var name = this.stuname;
          this.stuname = this.$refs.btn1.$el.innerText;
          //this.$refs.btn1是取上面id为btn1的元素(说id是不严谨的)
          this.$refs.btn1.$el.innerText = name
      }
  },
  created() {
   
  },
  mounted() {
      
  }
};
</script>

Guess you like

Origin blog.csdn.net/qq_39072819/article/details/103797733