[关闭]
@2890594972 2018-07-09T01:14:27.000000Z 字数 1562 阅读 903

vue全家桶与vue-router 知识点01

vue


vue全家桶

vue框架
请求数据:vue-resource ,替代我们的jquery,或者原生ajax封装
单页面路由: vue-router ,替代我们原生的路由
懒加载: vue-load-lazy ,优化页面图片加载
通讯机制: vuex,解决vue原生组件件通讯成本高的问题

脚手架安装vue2.0

安装教授vue-cli
安装:npm install -g vue-cli
vue init webpack 项目名
eg: vue init webpack vue-tuan

脚手架安装项目过程

  1. PS D:\bwclass\1506webB\examples\vue1023> vue init webpack vue-tuan
  2. ? Project name vue-tuan
  3. ? Project description 组件化开发我们之前的团购
  4. ? Author daxiang
  5. ? Vue build standalone
  6. ? Install vue-router? Yes
  7. ? Use ESLint to lint your code? No
  8. ? Setup unit tests with Karma + Mocha? No
  9. ? Setup e2e tests with Nightwatch? No
  10. vue-cli · Generated "vue-tuan".
  11. To get started:
  12. cd vue-tuan
  13. npm install
  14. npm run dev
  15. Documentation can be found at https://vuejs-templates.github.io/webpack

vue-router 路由使用

分三步:第一步引入路由

  1. import Router from 'vue-router'

第二步:启用用来

  1. Vue.use(Router)

第三步:创建路由配置

  1. new Router({
  2. routes: [//代表多个组件
  3. {//代表映射一个组件
  4. path:'',//组件路径
  5. component: List //注意组件大写
  6. }
  7. ]
  8. })

组件化开发,使用组件分几步

大概三步
第一步: 定义组件 .vue文件

  1. <template>
  2. <section>
  3. home
  4. </section>
  5. </template>
  6. <script>
  7. export default {
  8. }
  9. </script>
  10. <style>
  11. </style>

第二步: 引入组件

  1. import Home from '@/components/Home'

第三步:使用组件

  1. export default new Router({
  2. routes: [
  3. {
  4. path: '/home',
  5. component: Home
  6. }
  7. ]
  8. })

注意:使用组件作为路由配置,也可以直接使用

组件化开发,组件结构是什么样

简化版的组件

  1. <template>
  2. </template>
  3. <script>
  4. export default {
  5. }
  6. </script>
  7. <style>
  8. </style>

详细版的组件

  1. <template>
  2. <div class="hello">
  3. <h1>{{ msg }}</h1>
  4. <h2>Essential Links</h2>
  5. <ul>
  6. <li>内容</li>
  7. </ul>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'HelloWorld',
  13. data () {
  14. return {
  15. msg: '1506'
  16. }
  17. }
  18. }
  19. </script>
  20. <!-- Add "scoped" attribute to limit CSS to this component only -->
  21. <style scoped>
  22. h1, h2 {
  23. font-weight: normal;
  24. }
  25. ul {
  26. list-style-type: none;
  27. padding: 0;
  28. }
  29. li {
  30. display: inline-block;
  31. margin: 0 10px;
  32. }
  33. a {
  34. color: #42b983;
  35. }
  36. </style>

yinxiang_4314245_1508981654147

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注