实现数据从后端拿取
在文件夹powershell上运行npm install express -save-dev
(express是node的一个框架会比较容易创建一个node的服务)
5632表示端口号,这边只需4位数字都可以
var express=require('express');
var app=express();
//发送get请求
app.get('/xxx',function(req,res){
res.send('我是xxx,xx123');
})
//一个node执行的监听
app.listen(5632,function(){
console.log('5632,网易严选中间件,已经运行!')
})
当页面也出现了,get请求的数据时,说明,node服务成功运行,
import axios from 'axios'
created(){
axios.get('http://localhost:5632/xxx')
.then(_d=>{
console.log(_d.data);
});
在这个位置
//解决跨域问题,网上成熟的解决方案,直接拷贝
app.all('*',function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-with");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By", ' 3.2.1')
res.header("content-Type", "application/json;charset=utf-8");
next();
})
然后实现这个滚动标签数据的获取
app.get('/get_tabBtnList',function(req,res){
var tabBtnList=['推荐','居家生活','服饰鞋包','美食酒水','个护清洁','母婴亲子','全球特色'];
res.send(tabBtnList);
})
因为修改了node中间件中的代码所以得把node重新启动
created(){
axios.get('http://localhost:5632/get_tabBtnList')
.then(_d=>{
console.log(_d.data);
this.tabBtnList=_d.data;
});
}