首页 > 其他 > 详细

vue-cli脚手架使用-- 初学者

时间:2017-05-02 21:57:29      阅读:330      评论:0      收藏:0      [点我收藏+]

第一步:

    安装环境:

   1. npm install webpack -g

   2. npm install vue-cli -g

   3. vue init webpack-simple

   出现

    技术分享

 

    4. npm install 

    5. npm install vue-router vue-resource --save

    6. npm run dev 

    出现下图  说明成功

    技术分享

 

    写代码正式开始:

         最简单的写法:

         直接在App-vue写如你的代码  如:

         技术分享

    2.使用组件写代码:component

        a. 在src目录下先建一个component目录  在目录里面创建一个firstcomponent.js文件 如图

   

        技术分享

       

第一步,引入。在<script></script>标签内的第一行写

import firstcomponent from ‘./component/firstcomponent.vue‘

第二步,注册。在<script></script>标签内的 data 代码块后面加上 components: { firstcomponent }。记得中间加英文逗号!!!

export default {
  data () {
    return {
      msg: ‘Hello Vue!‘
    }
  },
  components: { firstcomponent }
}

第三步,使用
<template></template>内加上<firstcomponent></firstcomponent>

<template>
    <div id="app">
    <img src="./assets/logo.png"> <h1>{{ msg }}</h1> <firstcomponent></firstcomponent> </div>
</template>

   完整代码:

   技术分享

 

 

路由:

  第一种: 在 main.js中路由  不推荐

   在component目录中创建secondconponent 文件

   在App.vue中写如  如图;

     技术分享

  在main.js中的代码:

   技术分享

 

   

  

    

vue-cli脚手架使用-- 初学者

原文:http://www.cnblogs.com/gaosen/p/6798563.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!