<template>
<view id='app'>
姓氏:<input style="background-color: antiquewhite;" type="text" v-model="name1">+
名字<input style="background-color: antiquewhite;" type="text" v-model="name2">
全称:<input style="background-color: antiquewhite;" type="text" v-model="name3">
</view>
</template>
<script>
export default {
onLoad() {},
data() {
return {
name1: '',
name2: '',
}
},
computed: {
// getter和setter
name3: {
// 自己数据受其他数据影响
get(vuevalue) {
console.log("get",vuevalue)
return this.firstname + "-" + this.lastname
},
// 自己数据变了想更改别人
set(value) {
console.log("set",value)
this.name1 = value.split("-")[0]
this.name2 = value.split("-")[1]
}
}
},
methods: {}
}
</script>
前端vue里computed的set和get用法
最新推荐文章于 2024-04-26 20:39:59 发布