cnpm install vue-cli -g
cd 目錄路徑 vue init webpack-simple first-vue
├─src // 開發目錄
│ ├─assets // 資源文件目錄,須要打包的放到該目錄下
│ │ ├─logo.png │ │ ├─App.vue // App.vue組件
│ ├─main.js // 預編譯入口
├─.babelrc // babel配置文件
├─.gitignore ├─index.html // 主頁
├─package.json // 項目配置文件
├─README.md ├─webpack.config.js // webpack配置文件
cd first-vue npm install
npm run dev
npm run build
<template>
<div id="firstcomponent">
<h1>標題</h1>
<a> 做者:{{ author }} </a>
</div>
</template>
<script type="text/javascript"> export default { data () { return { author: "ling" } } } </script>
<style>
</style>
<import firstcomponent from './components/firstcomponent.vue'>
export default { name: 'app', data () { return { msg: 'Welcome to Your Vue.js App' } }, components: { firstcomponent } }
<template>
<div id="app">
<img src="./assets/logo.png">
<h2>{{msg}}</h2>
<firstcomponent></firstcomponent>
</div>
</template>
cnpm install vue-router --save
<template>
<div >
<h1>我是View1</h1>
<a> 我是View1 </a>
</div>
</template>
<script type="text/javascript"> export default { name: 'view1', } </script>
<style>
</style>
<template>
<div >
<h1>我是View2</h1>
<a> 我是View2</a>
</div>
</template>
<script type="text/javascript"> export default { name: 'view2', } </script>
<style>
</style>
import Vue from 'vue' import Router from 'vue-router' import View1 from './views/view1.vue' import View2 from './views/view2.vue' Vue.use(Router) export default new Router({ linkActiveClass: 'active', // 路由配置
routes: [ { path: '/view1', component: View1 }, { path: '/view2', component: View2 }, { path: '/*', component: View1 } ] })
import Vue from 'vue' import App from './App.vue' import router from './router.js'
new Vue({ el: '#app', router, render: h => h(App) })
<router-link to="/view1">Go to view1</router-link>
<router-link to="/view2">Go to view2</router-link>
<!-- 路由出口 -->
<!-- 路由匹配到的組件將渲染在這裏 -->
<router-view></router-view>
cnpm install axios --save
import Vue from 'vue' import axios from 'axios' import App from './App.vue' import router from './router.js' Vue.prototype.$ajax = axios new Vue({ el: '#app', router, render: h => h(App) })
<script type="text/javascript"> import axios from 'axios' export default { name: 'view1', mounted: function() { axios.post('/jhb/getslides') .then(function (response) { console.log(response); }) .catch(function (response) { console.log(response); }); } } </script>