說明:路由的params對象使用,必須要通過路由名來調用路由,而不能通過path來調用,而query對象則沒有這個要求。
1.query方式傳參和接受參數
1 傳參 2 this.$router.push({ 3 path:'/xxx' 4 query:{ 5 idname:id 6 } 7 })
接收的方式:this.$route.query.id
2.params方式傳遞參數
1 傳參:
2 this.$router.push({ 3 name:'路徑名稱' 4 query:{ 5 idname:id 6 } 7 })
接收的方式:this.$route.params.id
3.query和params的區別,query相當於get請求,在頁面跳轉的時候,可以在地址欄看到請求參數,然而params則相當於post請求,參數不會在地址欄中顯示。
++++++++++++++
axios:
首先,有時候直接安裝 axios 在 vuecil 會報錯
先安裝!
npm install axios
然后!
npm install --save axios vue-axios
配置模板!
import Vue from 'vue' import axios from 'axios' import VueAxios from 'vue-axios' Vue.use(VueAxios, axios)
在腳手架里面的用法!
Vue.axios.get(api).then((response) => { console.log(response.data) }) this.axios.get(api).then((response) => { console.log(response.data) }) this.$http.get(api).then((response) => { console.log(response.data) })
PS。平時在別的地方也用 axios 挺好用的
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>