vue中的computed用法

<template>
<div>
<input v-model="first"></input>
<input v-model="second"></input>
<input v-model="action"></input>
</div>
</template>

<script>
// import { set } from 'js-cookie'

export default {
data() {
return {
'first': 'tom',
'second': 'eat'
// 'action': ''
}
},
computed: {
action: {
get() {
return this.first + '-' + this.second
},
set(val) {
this.first = val.split('-')[0]
this.second = val.split('-')[1]
}
}
}
}

</script>
posted @ 2022-07-14 20:21  虚渡  阅读(93)  评论(0编辑  收藏  举报