当前位置:网站首页>[uniapp] the uniapp mobile terminal uses uni Troubleshooting of navigateback failure

[uniapp] the uniapp mobile terminal uses uni Troubleshooting of navigateback failure

2022-06-26 17:22:00 A dying salted fish

Technology used in the project :
uniapp The navigation bar at the bottom of the mobile terminal uses colorUI Customized in , Not at all uniapp Born in the Central Plains tabbar
Current issues :
A little different tabbar Different... Can be displayed UI page , The key is the page UI All in one URL In the address , That is to say, no matter which one you switch to tabbar, The root path is displayed : /.
 Insert picture description here
Current demand :
It needs to be implemented on a successful order page , Click on < Go back two pages to the mall list page , And the corresponding highlighted... Should be displayed at the bottom tabbar, With uni.navigateBack There is no effect , The specific reason is still unclear .
It was used this.$router.go(-2) There is no problem with the implementation on the browser simulation side , But it still can't be packed on the mobile phone , Here's the picture :
 Insert picture description here
So I started searching aimlessly bug, Try the solution …
It was found later that uniapp Of uni.$emit() Trigger global custom event , You can write the parameters to be carried into the object , And then use uniapp Of uni.$once() Listen for global custom events , Event by uni.$emit Trigger , But only triggered once , Remove the listener after the first trigger
 Insert picture description here
 Insert picture description here
And then through uni.navigateTo Page Jump , This requirement can be realized
Specific code implementation :

<script>
  //  Order success page 
  export default {
    
    name: 'orderSuccess',
    methods: {
    
      gotoMall() {
    
        //  Go to the mall page , Here we use uni.navigateBack It will fail 
        // this.$router.go(-2)  This method can be simulated on the browser side , But there is a problem on the mobile phone 
        uni.$emit('changeBar', {
    
          //  Bring the required  mall  Field 
          paramsName: "mall"
        })
        uni.navigateTo({
    
          //  Jump directly to the home page ( It has been done in the home page tabbar Highlight the mall icon )
          url: '/pages/index/index'
        })
      },
    }
  }
</script>
<script>
	//  home page 
	export default {
    
		onShow() {
    
		  //  Global monitoring uni.$emit Parameters transmitted 
	      uni.$once('changeBar', function(data) {
    
	      	//  explain : as long as PageCur Is changed to  mall, At the bottom of the first page tabbar The mall icon will be highlighted 
	        this.PageCur = data.paramsName
	        console.log(' Listening for events from  changeBar , The carried parameter is :' + data.paramsName);
	      })
   	 }
	}
</script>
原网站

版权声明
本文为[A dying salted fish]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261651503020.html