美文网首页
Vue 入门实例

Vue 入门实例

作者: _Wake | 来源:发表于2017-03-03 01:21 被阅读112次

一、模块
1.创建Vue模版文件header.vue,定义模块

// header.vue
<template>
  <div class="header">
      I am header
  </div>
</template>
<script type="text/ecmascript-6">
  export {}
</script>

2.父文件中引入、注册、使用

// app.vue
<template>
  <div id="app">
    <v-header></v-header>                                  // 使用
  </div>
</template>

<script type="text/ecmascript-6">
  import header from './components/header/header.vue'      // 引入

  export default {
    components: {
      'v-header': header                                   // 注册
    }
  }
</script>

三、父组件向子组件传值

// 父组件
<template>
  <component-a  msgfromfather="Hello component"> </component-a>
</template>

<script>
import ComponentA from './components/componentA.vue'
export default {
  data () {
  },
  components: { ComponentA },
}
</script>
// 子组件 ComponentA
<template>
  <h1> {{ msgfromfather }} </1h>
</template>

<script>
export default{
  data () {
  },
  props: ['msgfromfather']  
}
</script>
/* Hello component */

四、子组件向父组件传值

// 子组件
<template>
  <button v-on:click="btnClick">Click me!</button>
</template>

<script>
export default{
  data () {
    return {
      msg: 'hello from component A!'
    }
  },
  methods: {
    btnClick: function () {
      this.$emit('child-event', this.msg)
    }
  }
}
</script>
// 父组件
<template>
  <component-a v-on:child-event="listenToBoy"></component-a>
  <p>child tells me :  {{ childWords }} </p>
</template>

<script>
import ComponentA from './components/componentA.vue'
export default{
  data () {
    return {
      childWords: ''
    }
  },
  components: { ComponentA },
  methods: {
    listenToMyBoy: function (msg) {
      this.childWords = msg
    }    
  }
}
</script>
/* Hello component */

五、todolist 知识点总结

// 循环、样式、事件
<li v-for="item in items" v-bind:class="{finished: bool}"  v-on:click="functionName(item)" >
  {{ item.label }}
</li>

// 数据绑定 、回车键触发事件
<input v-model="newItem"  v-on:keyup.enter="addNew"> 

六、css动画

      transition all 0.5s
      backdrop-filter blur(10px)
      &.fade-transition
        opacity 1
        background rgba(7, 17, 27, 0.8)
      &.fade-enter,&.fade-leave
        opacity 0
        background rgba(7, 17, 27, 0)

七、条件样式

// template
<div class="logo" :class="{'highlight': totalCount > 0}">如果数量大于0就渲染这个样式</div>

// style
  .logo
    position: absolute
    ...
    &.highlight
      color #fff  

八、计算属性

// payDesc 作为一个变量在页面中通过 {{payDesc}} 渲染,用于不同状态下,显示不同的内容
computed: {
    payDesc() {
        if (this.totalPrice === 0) {
            return `¥${this.minPrice}元起送`
        } else if (this.totalPrice < this.minPrice) {
            return `还差¥${this.minPrice - this.totalPrice}元起送`
        } else {
            return '去结算'
        }
    }
}

相关文章

  • 01vue-安装vue

    资源 1.Vue.js2.0从入门到放弃---入门实例(一)2.Vue.js入门学习(一)3.Vue官方中文Api...

  • vue2.0第四季—实例和内置组件

    第1节 实例入门-实例属性 (一vue和jqueryjs一起使用)一,Vue和JQuery.js一起使用 下载并...

  • vue-cli入门(二)-vue-cli2.0的项目结构和入门实

    基于vue-cli2.0,推荐: vue-cli入门(三)——人员管理实例 1.执行:npm run build ...

  • Vue 入门实例

    一、模块1.创建Vue模版文件header.vue,定义模块 2.父文件中引入、注册、使用 三、父组件向子组件传值...

  • electron

    electron vue桌面应用入门实例 从零开始搭建,基于electron vue cli3 的桌面应用。git...

  • Vue 学习笔记入门篇-数据绑定,指令,事件

    Vue 学习笔记入门篇-数据绑定,指令,事件 2.1.1 vue 实例和数据绑定 通过构造函数 Vue 就可以创建...

  • 实例学习vue.js目录

    目录 入门篇 初识vue vue基础指令 vue实例:标语大作战 事件修饰符 双向数据绑定 使用v-for遍历数据...

  • Vue入门:Vuex 实例

    如果你在使用 vue.js , 我想你可能会对 vue 组件之间的通信感到崩溃 。哪有没有解决办法呢? Vuex:...

  • Vue2.0 豆瓣电影项目实例

    vue-movie vue2.0 豆瓣电影项目实例,包含三个功能模块(首页列表、搜索列表、详情页) ,适合刚入门学...

  • 第3章 Vue 基础精讲

    3-1 Vue实例 vue实例是根实例,组件也是vue实例,所以说页面是由很多vue实例组成的data(): 以d...

网友评论

      本文标题:Vue 入门实例

      本文链接:https://www.haomeiwen.com/subject/dqclgttx.html