父
<template>
<div>
<test3-a :value="value"
@input="handleChange"></test3-a>
</div>
</template>
<script>
import test3A from '../components/test3-a.vue'
export default {
components: { test3A },
data () {
return {
value: 1
}
},
methods: {
handleChange (val) {
this.value = parseInt(val)
}
}
}
</script>
子
<template>
<div>
<button @click="increase(-1)">减1</button>
<span> {{currentValue}} </span>
<button @click="increase(1)">加1</button>
</div>
</template>
<script>
export default {
props: {
value: {
type: Number
}
},
data () {
return {
currentValue: this.value
}
},
methods: {
increase (val) {
this.currentValue = this.value + val
this.$emit('input', this.currentValue)
}
}
}
</script>
props不支持直接修改