天天看點

vue query傳參重新整理後資料變成“[Object Object]“

寫法:

this.$router.push({
	path: '/index',
    query: obj    //直接傳遞參數,且參數是一個對象 
 })
           

以這種方式傳遞參數,且參數為一個對象,重新整理頁面後可能會出現“[Object Object]”

解決方案:

this.$router.push({
	path: '/index',
    query: {
     obj: JSON.stringify(obj)  // 将對象轉成json字元串
	}
 })
//在取參數的時候處理一下:  JSON.parse(this.$route.query.obj)
           

 通過上述方案可以避免出現"[Object Object]"現象