本文介绍了webpack+vuex+axios 跨域请求数据的示例代码,分享给大家,具体如下:
使用vue-li 构建 webpack项目,修改bulid/config/index.js文件
在action.js 中想跨域请求
设置action.js:
export const GET_IN_THEATERS = ({
dispatch,state,commit
}) => {
axios({
url: '/v2/movie/in_theaters'
}).then(res => {
commit('in_theaters',res.data)
})
}
dispatch,state,commit
}) => {
axios({
url: '/v2/movie/in_theaters'
}).then(res => {
commit('in_theaters',res.data)
})
}
组件内使用: