gpt4 book ai didi

javascript - Vue JS 中等于 "="和冒号 ":"符号有什么区别?

转载 作者:行者123 更新时间:2023-12-01 01:09:18 25 4
gpt4 key购买 nike

我有一个onSubmit() Vuejs 中的方法。无法弄清楚等于 = 之间有什么区别和冒号:符号。这是以下代码

methods:{
onSubmit(){
let product= {
name: this.name,
review: this.review,
rating: this.rating
},
this.name=null,
this.review=null,
this.rating=null
}
}

在上面的函数中,我将值存储在名为 product 的对象中,存储值后我分配 null数据变量的值。

为什么我们将值传递给product对象使用 :并使用 = 到数据对象标志?

最佳答案

{
name: this.name,
review: this.review,
rating: this.rating
}

这会创建一个对象,它是一个数据结构。

let product = {}

在这里,您将对象(数据结构)分配给变量。

关于javascript - Vue JS 中等于 "="和冒号 ":"符号有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55300500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com