为什么VUE计算在设置函数中设置因值之后,呼叫获取?
我将计算值定义为波纹
模板:
<date-picker
v-model="rangeDate"
type="date"
format="jYYYY/jMM/jDD"
display-format="jYYYY/jMM/jDD"
input-class="vgt-input"
:state="errors.length > 0 ? false : null"
:placeholder="$t('fields.ads.rangeDate')"
clearable
range
/>
{{rangedate}}
脚本:
data: () => ({
body: {}
),
computed: {
rangeDate: {
get() {
return [this.body.sdate, this.body.fdate]
},
set(newVal) {
// console.log(newVal)
if (newVal.length === 0) {
this.body.sdate = ''
this.body.fdate = ''
} else if (newVal.length === 1) {
this.body.sdate = newVal[0]
this.body.fdate = `${newVal[0]}`
} else {
this.body.sdate = newVal[0]
this.body.fdate = `${newVal[1]}`
}
},
},
},
此值用于范围日历改变。
我认为必须在每个依赖值更改后重新计算计算值,但是当相关值变化时,设置函数不会导致调用get get函数。 请帮我。
I define a computed value as bellow
template :
<date-picker
v-model="rangeDate"
type="date"
format="jYYYY/jMM/jDD"
display-format="jYYYY/jMM/jDD"
input-class="vgt-input"
:state="errors.length > 0 ? false : null"
:placeholder="$t('fields.ads.rangeDate')"
clearable
range
/>
{{rangeDate}}
script:
data: () => ({
body: {}
),
computed: {
rangeDate: {
get() {
return [this.body.sdate, this.body.fdate]
},
set(newVal) {
// console.log(newVal)
if (newVal.length === 0) {
this.body.sdate = ''
this.body.fdate = ''
} else if (newVal.length === 1) {
this.body.sdate = newVal[0]
this.body.fdate = `${newVal[0]}`
} else {
this.body.sdate = newVal[0]
this.body.fdate = `${newVal[1]}`
}
},
},
},
this value is used for range calendar but by setting that through v-model it set the sdate and fdate correctly but in other places of template that show rangeDate won't change.
I thought the computed value must be recalculated after the change of each depended values but when the dependent values change in set function don't cause to call get function.
please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我了解,更改对象的价值不会影响提高手表方法。
I understood that changing the value of an object does not affect raising the watch method.