vue axios get/post 请求 数组参数
搜索功能含多选就涉及到数组参数的传递,比如 id=[1,2,3,4],后台接收的参数类型为 id=1&id=2&id=3$id=4,引入qs对传递的参数进行处理
get请求:对参数params进行处理
export function shareConfig(query) {
return request({
url: "/device",
method: "get",
params: query,
paramsSerializer: params => {
return qs.stringify(params, { indices: false });
}
});
}
post请求:对参数data进行处理
export function restart(data) {
return request({
url: "/instruct",
method: "post",
data: qs.stringify(data, { indices: false })
});
}
子组件向父组件传递多个参数的写法:
// 子-传
this.$emit("change", param1, param2);
// 父-接收,使用参数arguments
<component :message="infoData" @change='handleComponent(arguments)' />
// methods
handleComponent(params) {
console.log(params)
}
Vue兄弟组件通信:
// 1.创建event-bus.js文件
import Vue from 'vue'
export const EventBus = new Vue()
// 2.发送事件组件
import { EventBus } from '@/utils/event-bus.js'
// 方法里面调用
EventBus.$emit(fucname,params)
// 3.接收事件组件
EventBus.$on(fucname,params =>{
// 数据处理
console.log(params)
})
// 移除事件监听
EventBus.$off(fucname,{})