说明:路由的params对象使用,必须要通过路由名来调用路由,而不能通过path来调用,而query对象则没有这个要求。

1.query方式传参和接受参数

query和params的区别,get请求和post请求!!,axios请求
1 传参
2 this.$router.push({
3    path:'/xxx'
4    query:{
5         idname:id
6       }
7 })
接收的方式:this.$route.query.id
query和params的区别,get请求和post请求!!,axios请求

2.params方式传递参数

query和params的区别,get请求和post请求!!,axios请求
1 传参:
2 this.$router.push({
3    name:'路径名称'
4    query:{
5         idname:id
6       }
7 })
接收的方式:this.$route.params.id
query和params的区别,get请求和post请求!!,axios请求

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)

在脚手架里面的用法!

query和params的区别,get请求和post请求!!,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)
})
query和params的区别,get请求和post请求!!,axios请求

 

PS。平时在别的地方也用 axios 挺好用的

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

相关文章:

  • 2021-12-17
  • 2021-11-23
猜你喜欢
  • 2021-12-14
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-10-18
相关资源
相似解决方案