账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue为什么我用var声明一个变量,然后把this赋值给那个变量变成双向绑定了
    34
    0
    shopCountEdit:function(pid , type){
                    var productData = this.productData;
                    var cartShop = this.cartShop;
                    var cartCount = this.cartCount;
                    var count = 0;
                    for (let i in productData) {
                        if(productData[i].id == pid){
                            if(productData[i].cartcount >= 0){
                                if(!cartShop[pid]){
                                    cartShop[pid] = new Object();
                                    cartShop[pid].id = pid
                                    cartShop[pid].delivertime = 0
                                    cartShop[pid].price = productData[i].price
                                    cartShop[pid].catid = this.classInfo.id
                                    cartShop[pid].count = 0
                                }
                                if(type == 0){
                                    var sum = parseInt(productData[i].cartcount) - 1;
                                    cartCount = parseInt(cartCount) - 1;
                                }else{
                                    var sum = parseInt(productData[i].cartcount) + 1;
                                    cartCount = parseInt(cartCount) + 1;
                                }
                                count = sum;
                                productData[i].cartcount = sum;
                                cartShop[pid].count = sum
                            }else{
                                productData[i].cartcount = 0;
                            }
                            break;
                        }
                    }
                    
                    var params = {
                        pid : pid,
                        count : count,
                        token : this.token
                    }
    
                    var url = 'index.php?g=Wap&m=Product&a=updateCart&'
                    var arr = []
                    for (var i in params) {
                        arr.push(i + '=' + params[i])
                    }
                    url = url + arr.join('&')
                    axios.get(url).then((response) => {
                        console.log(response.data.status)
                        if(response.data.status == 1 || response.data.status == 403){
                            this.productData = productData
                            this.cartShop = cartShop;
                            this.cartCount = cartCount;
                            console.log(321)
                        }else if(response.data.status > 402){
                            this.msgContent = response.data.msg;
                            this.msgModel = true;
                        }
                    })
                },

    1.我想异步判断是不是超出,如果没超出才赋值回this里面,但现在他直接没经过异步就双向绑定了

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 先生你狠拽 普通会员 1楼

      在 Vue 中,var 是一个用于声明变量的保留字。当你在 var 声明一个变量时,这个变量立即成为全局变量。然后,当你试图在其他地方使用这个变量时,Vue 将使用全局变量,而不是本地变量。

      例如: ```javascript var name = "John Doe";

      // 在组件中使用 this this.name = "Jane Doe";

      // 在另一个组件中使用 this this.$parent.name = "John Doe"; ```

      在上面的示例中,this 的值在全局作用域中,而不是在组件的作用域中。这意味着我们不能在组件的内部更改 this 的值。

      如果你想在组件内部更改 this 的值,你需要使用箭头函数或其他异步函数。例如: ```javascript var name = "John Doe";

      // 在组件内部使用箭头函数 this.$emit("name-changed", "Jane Doe");

      // 在另一个组件中使用箭头函数 this.$nextTick(() => { this.$emit("name-changed", "John Doe"); }); ```

      在这个示例中,我们使用箭头函数在组件内部改变 this 的值,并在另一个组件中使用箭头函数再次改变 this 的值。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部