Vue
vue-cli
vue init webpack fileName
npm run dev
后端api交互
真的弄了好长时间
1 2
| npm install axios npm install --save axios vue-axios
|
1 2 3 4 5
| import axios from 'axios' import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
|
1 2 3 4 5 6 7 8 9 10 11 12
| data() { return { info: null } }, mounted() { this.axios .get("api接口url") .then(response=>(this.info = response)) .catch(function(error){console.log(error)}) }
|
前端路由
What
How
1 2
| 安装 npm install vue-router
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import VueRouter from 'vue-router' import Hitokoto from './components/hitokoto'
Vue.use(VueRouter)
const router = new VueRouter({ routes:[ {path:'/', component: Hitokoto} ] })
new Vue({ el: '#app', components: { App }, template: '<App/>', router })
|
常用v-
v-on
:略写@
v-bind
:略写:
绑定各种属性
v-for
:
v-html
:输出html
v-if
和v-show
:if
v-model
:双向绑定