Vue进行前后端数据交互,我说一下我学习的方法
- 建一个.js文件,获取后端的URL
export default {
getTest(data, namespace) {
return axios.request({
url: `......`,
method: "post",
data: data
});
}
};
- 获取数据
async get(queryObj) {
let namespace = this.namespace;
try {
const res = await testTotal.getTest(
queryObj,
namespace
);
if (res.status === 200) {
let data = res.data;
if (data.code === 200) {
let result = data.result;
this.dealEcharts(result);
}
}
} catch (e) {
this.$message.warning("暂无数据");
console.log("e");//查看传值情况并使用
console.log(e);
}
},