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
})