vue对ref中_value的问题

img


在如上图中,一次输入1,2,3 第一次watch返回1,第二次返回12,第三次123,
而三次捕获到的_value分别为 ,1,12
最新输入的未捕获到
但使用this.$refs.qq._value获得的值无法获得最新存储的完整内容
组件代码如下:

<template>
<div>
  <h1>{{ name }}h1>
  <h1>{{ age }}h1>
  <br />
  <div>
    <input type="text" ref="qq" v-model="v" placeholder="请输入内容" />
    <h2>{{ v }}h2>
  div>
div>
template>

<script>
export default {
name: 'student',

data() {
  return {
    name: '云墨',
    age: '19',
    v: ''
  }
},
watch: {
  v: {
    handler(newvalue, oldvalue) {
      console.log('修改前:' + oldvalue + '修改后' + newvalue)
      this.show()
    }
  }
},
methods: {
  show() {
    console.log('这是show方法,获得的value' + this.$refs.qq)
    console.log('@@这是show方法,获得的value', this.$refs.qq._value)
    console.log(this.$refs)
    console.log('##这是show方法,获得的value', this.$refs.qq._value)
  }
}
}
script>


跟着视频学了没多久,请大家赐教

如果想回去最新的值可以绑定 @input事件可以获取最新的值

this.$refs.qq.value 试试

this.$refs.qq看下里面有值没

img

show() {
console.log('这是show方法,获得的value' + this.$refs.qq)
console.log('@@这是show方法,获得的value', this.$refs.qq.value)
console.log(this.$refs)
console.log('##这是show方法,获得的value', this.$refs.qq.value)
}