关于vue.js:Vue-thisrefs的使用

1次阅读

共计 375 个字符,预计需要花费 1 分钟才能阅读完成。

<template>
  <div class="hello">
    <h1>{{msg}}</h1>
    <div id="test" ref="div1">
        <input type="text" ref="input1" name="name" />
        <button @click="add"> 增加 </button>
    </div>  
  </div>

</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {msg: 'Welcome to Your Vue.js App'}
  },
  methods:{add(){
        // this.$refs.input1.value  = '22';
        let input1 = this.$refs.input1;
        let div1 = this.$refs.div1;
        console.log(input1,div1);
      }
    }
}
正文完
 0