当前位置:网站首页>Uni app wechat applet ordering system [another order] page Jump

Uni app wechat applet ordering system [another order] page Jump

2022-07-19 02:35:00 Tamarind_

1 Like hungry Click on 【 Another one 】 The effect of

2 When you click on another order , Get the order of this order id, Jump to the page , By order id  Get the goods in the order id, Query products id, The goods must be on the shelves / Inventory cannot be 0 etc. .

3 After the item is successfully added , Click again on the 【 Another one 】, Did not continue to add items to the shopping cart , But it will jump .

4 Adding other products can Add to the shopping cart

--------------------------------------------------------------------------------------------------

 

Problems encountered :

Click on 【 Another one 】 When I jump to the page , The goods have been successfully added to the shopping cart . Every time you enter the shopping cart from another page , Add the same items to the shopping cart .

Code :

template in :
<button type="primary" plain hover-class="none" @tap="onceMore(order.orderId)"> Another one </button>

methods in :
onceMore(orderId) {
	if(orderId != '') {
		uni.setStorageSync('orderId', orderId);
		uni.switchTab({
			//  Another one 
			url:"/pages/index/index"
		})
	}
}

/pages/index/index.vue:

script in :
onShow() {
    this.orderId = '';
    this.type = '';
    this.orderId = uni.getStorageSync('orderId');
    console.log("this.orderId="+this.orderId);
    if(this.orderId != '' && this.orderId != undefined && this.type != '' && this.type != undefined) {
        if(!this.cartFlag) {
        	this.getAddCartGoods(this.orderId, this.type);
        }
    }
},

 

analysis :

① Think it's onShow problem .

So will onShow and onLoad Changed many times , So I have the following understanding .

-----onShow and onLoad The difference between -----

onShow: Every time you switch pages and then switch back, you will reload

onLoad: Load the page only once , Switching pages will not load

It's not about it .

② Guess if there is a cache problem .

So I checked switchTab The value of the setStorageSync And receive parameters getStorageSync.

stay uni-app Official website Found the relevant introduction (https://uniapp.dcloud.io/api/storage/storage?id=setstoragesync

 

 

 

setStorageSync Is stored in the local cache ,getStorageSync Is to get values from the local cache . Then when I switch pages, the value transfer always exists , So every page switch , When switching back to the page of adding to the shopping cart, products will be added to the shopping cart . Even if you don't click another order, it will accumulate .

I happened to see it on the official website removeStorage.

 

 

So in index.vue Added code :

script in :
onShow() {
    this.orderId = '';
    this.type = '';
    this.orderId = uni.getStorageSync('orderId');
    console.log("this.orderId="+this.orderId);
    //  Clear the cache of orderId, But the page has been obtained orderId, Use global variables directly 
    uni.removeStorage({
       key: 'orderId',
           success: function (res) {
           console.log('success');
       }
    });
    if(this.orderId != '' && this.orderId != undefined) {
        if(!this.cartFlag) {
        	this.getAddCartGoods(this.orderId);
        }
    }
},

 

This solves the problem .

 

原网站

版权声明
本文为[Tamarind_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207170008556963.html