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

第一步:vue

    安装环境:webpack

   1. npm install webpack -gweb

   2. npm install vue-cli -gvue-router

   3. vue init webpack-simplevue-cli

   出现npm

    

 

    4. npm install app

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

    6. npm run dev spa

    出现下图  说明成功3d

    

 

    写代码正式开始:

         最简单的写法:

         直接在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中的代码:

   

相关文章
相关标签/搜索