query和params的区别,get请求和post请求!!,axios请求

说明:路由的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>
原文地址:https://www.cnblogs.com/zwjun/p/11523505.html