小言_互联网的博客

vue的学习与总结

403人阅读  评论(0)

一、vue项目的目录结构

二、vue的运行流程

 index.html—>main.js—>App.vue—>router/index.js

1.index.html(项目页面入口)


  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0">
  6. <title>myvue </title>
  7. </head>
  8. <body>
  9. <div id="app"> </div>
  10. <!-- built files will be auto injected -->
  11. </body>
  12. </html>

2. main.js(核心文件)


  
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import App from './App'
  5. import router from './router'
  6. //引入IVIEW组件
  7. import iView from 'iview';
  8. import 'iview/dist/styles/iview.css';
  9. Vue.use(iView);
  10. //引入vue-easytable
  11. import 'vue-easytable/libs/themes-base/index.css'
  12. import {VTable,VPagination} from 'vue-easytable'
  13. Vue.component(VTable.name, VTable)
  14. Vue.component(VPagination.name, VPagination)
  15. //引入axios
  16. import axios from 'axios'
  17. Vue.prototype.$ajax = axios
  18. Vue.config.productionTip = false
  19. /* eslint-disable no-new */
  20. new Vue({
  21. el: '#app',
  22. router,
  23. components: { App },
  24. template: '<App/>'
  25. })

3.App.vue(项目入口文件)


  
  1. <template>
  2. <div id="app">
  3. <img src="./assets/logo.png">
  4. <router-view/>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'App'
  10. }
  11. </script>
  12. <style>
  13. #app {
  14. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  15. -webkit-font-smoothing: antialiased;
  16. -moz-osx-font-smoothing: grayscale;
  17. text-align: center;
  18. color: #2c3e50;
  19. margin-top: 60px;
  20. }
  21. </style>

4.router/index.js(路由组件)

vue-router

vue-router是vue的核心插件,使用vue-router,我们可以将组件映射到路由,然后告诉vue-router在哪里渲染它们。


  
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import HelloWorld from '@/components/HelloWorld'
  4. import TableMain from '@/components/TableMain'
  5. Vue.use(Router)
  6. export default new Router({
  7. routes: [
  8. {
  9. path: '/',
  10. name: 'Table',
  11. component: TableMain
  12. }
  13. ]
  14. })

 

 

 


转载:https://blog.csdn.net/sherazade/article/details/105427176
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场