<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看下里面有值没
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)
}