header(‘Access-Control-Allow-Origin:*‘);//允许所有来源访问 header(‘Access-Control-Allow-Method:POST,GET‘);//允许访问的方式
proxyTable: { ‘/api‘: { target: ‘填写请求源地址‘, //源地址 changeOrigin: true, //是否跨域 pathRewrite: { ‘^/api‘: ‘‘ //路径重写 } } }
this.$axios.post("/api/地址",{ 发送的数据 }).then(data=>{ console.log(data); })
axios.defaults.headers.post["Content-type"]="application/json";
Vue.prototype.$axios=axios;
fetch("/api/test/testToken.php",{
method:"post",
headers:{
"Content-type":"application/json",
},
body:JSON.stringify({发送数据})
}).then(result=>{
return result.json()
}).then(data=>{
console.log(data);
})
methods: { getData () { var self = this $.ajax({ url: ‘地址‘, type: ‘GET‘, dataType: ‘JSONP‘, success: function (res) { self.data = res.data.slice(0, 3) self.opencode = res.data[0].opencode.split(‘,‘) } }) } }
原文:https://www.cnblogs.com/SallyShan/p/11638149.html