标签:assets origin nod 豆瓣 转发 const console import pat
cnpm install -g vue-cli
vue init webpack 英文项目名
cnpm install
npm run dev
npm install --save axios vue-axios
import Vue from ‘vue‘
import axios from ‘axios‘
import VueAxios from ‘vue-axios‘
Vue.axios({
method: ‘get‘,
url: url,
}).then(res => {
console.log(res.data);
})
dev: {
env: require(‘./dev.env‘),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: ‘static‘,
assetsPublicPath: ‘/‘,
//跨域
proxyTable: {
//请求路径以api开头的,转发到 target地址去请求
‘/api‘: {
target: ‘https://api.douban.com/‘,
changeOrigin: true,
//将路径中的/api 替换成 /
pathRewrite: {
‘^/api‘: ‘/‘
}
}
}
}
getData() {
//api开头的都会由代理服务器转发到 http3://api.douban.com的域名去请求,因为在config/index.js中已经配置了
let url = ‘/api/v2/movie/in_theaters‘;
Vue.axios({
method: ‘get‘,
url: url,
//豆瓣的数据获取接口需要传递header,并且Content-Type不能指定为json,否则请求不到数据
headers: {
‘Content-Type‘: ‘application/text‘
}
}).then(res => {
console.log(res.data);
})
}
npm i element-ui -S
import ElementUI from ‘element-ui‘
import ‘element-ui/lib/theme-default/index.css‘
Vue.use(ElementUI)
cnpm install vue-router -D
import VueRouter from ‘vue-router‘
Vue.use(VueRouter)
const routes = [
{
path:‘/‘,
component:Todos
},
{
path:‘/todo/:id‘,
component:Todo
}
];
const router = new VueRouter({routes})
new Vue({
el:‘#app‘,
template:‘<App/>‘,
components:{App},
router
})
标签:assets origin nod 豆瓣 转发 const console import pat
原文地址:http://www.cnblogs.com/MrsQiu/p/7082577.html