node.js中的后台数据请求mock,axios
2020-04-03 07:03
531 查看
<!-- axios 处理cross跨域 后台配置好的
1.安装 cnpm install --save-dev axios
2.引入axios 到项目 或者组件(仅限当前组件使用) --> // 使用axios 请求 Axios.get("/getuser") .then(res => { //succss console.log(res.data.result); }) .catch(error => { //error console.log(error); }) .finally(() => { console.log("最后执行的操作"); }); Axios.post("/gettable") .then(res => { //succss console.log(res.data.result); }) .catch(error => { //error console.log(error); }) .finally(() => { console.log("最后执行的操作"); }); //例如get后台的api接收参数 // Axios.get("http://www/maodou.com/getdata?id=1&name=zhangsnan") // .then(res => { // //succss // console.log(res); // }) // .catch(error => { // //error // console.log(error); // }) // .finally(() => { // console.log("最后执行的操作"); // }); // Axios.get("", { // params: { // id: 1, // name: "张三" // } // }) // .then(res => { // //succss // console.log(res); // }) // .catch(error => { // //error // console.log(error); // }) // .finally(() => { // console.log("最后执行的操作"); // }); //例如post后台的api接收参数 // Axios.post("", { // id: 1, // name: "张三" // }) // .then(res => { // //succss // console.log(res); // }) // .catch(error => { // //error // console.log(error); // }) // .finally(() => { // console.log("最后执行的操作"); // }); //因为axios 返回的是一个promise 对象 //就可以使用es6 async // async function (){ // } computed: { //计算属性 //computed 里面可以写复杂的逻辑 // 里面也可以写 getter setter // getData() { // console.log("计算属性里面的方法"); // }, getData: { get() { //getter return this.num1 * this.num2; }, set(newValue) { //setter this.num1 = newValue; this.num2 = newValue / 10; } }, changeStatus() { console.log("在事件执行的方法里面调用"); }
},
watch: {
// watch 监听属性 或者 是 watch 监听组件上的数据变化的
//watch 监听里面写的监听方法和 变量同名 同能才能监听到变量的变化
msg(afterValue, beforeValue) {
console.log(afterValue, beforeValue);
}
},
beforeCreate() {},
created() {},
beforeMount() {},
mounted() {
//在挂载完成之后去执行
//computed 里面的方法在调用的时候不需要添加括号执行
//this.getData; //属性
this.getData = 100;
console.log(this.getData);
},
beforeUpdate() {},
updated() {},
beforeDestroy() {},
destroyed() {}
};
<!-- vue-resource 插件
1.cnpm install --save-dev vue-resource 安装
2.配置项目使用 mainjs
vue 项目使用mockjs 模拟后台数据 1.安装 cnpm install mockjs --save-dev 2.配置mockjs模拟数据的文件 3.引入mock 到vue项目 去mainjs -->
相关文章推荐
- VUE—axios的get请求向后台发送数据(图文详情)
- vue当中axios调取后台数据 以及设置自定义请求头
- vue.js数据请求方式axios和fetch
- $axios请求后台数据或Failed to read HTTP message
- mock.js在vue中的使用(axios请求数据)
- 基于node.js依赖express解析post请求四种数据格式
- 详解node.js搭建代理服务器请求数据
- node+mysql+ajax+javascript搭建一套服务接口,实现前后台数据请求
- node.js中axios使用心得总结
- node.js依赖express解析post请求四种数据格式()
- MOCK.JS 生成随机数据,拦截 Ajax 请求
- ReactJS +jQuery+Node后台取数据
- Android向node.js编写的服务器发送数据并接收请求
- ajax请求后台接口数据与返回值处理js的实例讲解
- PHP后台2:客户端(IOS/Android)Post请求以及JSON数据编解码
- vue通过axios发送put/post等请求,配合后台consume"MediaType.APPLICATION_FORM_URLENCODED"
- node.js接收post请求,并把数据push到redis
- vue+Nodejs(koa),form表单使用ref发送数据以及后台输出数据
- 转载:ionic+nodejs开发遇到的跨域和post请求数据问题
- js页面用定时任务通过AJAX获取后台数据,但是从这个页面跳转到其他页面后,定时任务仍然在定时请求后台