构建用户界面的javascrapt框架,用于自动生成html
轻量、灵活、数据驱动视图
引入vue
<script src="vue.js"></script>
展示html
<div id="app">
Vue<input type="text" v-model="msg">
<p></p>
</div>
建立vue对象
new Vue({
el:"#app", # 表示在当前这个元素内开始使用Vue
data:{
msg:"",
}
})
npm install vue-cli -g
vue-init webpack 项目名
A Vue.js project
npm install
for you after the project has been created? (recommended)
开启项目
cd 项目名
npm run dev
配置路由,index.js文件中配置
import Vue from 'vue'
import Router from 'vue-router'
import Index from '../components/index.vue'
import News from '../components/news.vue'
import Login from '../components/login.vue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Index',
component: Index
},
{
path: '/index',
name: 'Index',
component: Index
},
{
path: '/news',
name: 'News',
component: News
},
{
path: '/login',
name: 'Login',
component: Login
},
]
})
import axios from 'axios'
Vue.prototype.$axios = axios
在vue组件中的script标签中的methods的函数中使用
test(){
let that = this
that.$axios.request({
url: '目标api地址',
method: 'GET',
}).then(function (response) {
console.log(response)
})
}