亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

01-vue基礎

標簽:
Vue.js

双向数据绑定

指令

v-model

双向绑定

v-text

v-html

v-bind

可以绑定html标签的任何一个属性
示例:

    <a href="#" v-html="msg" v-bind:title="tip" v-bind:pid="id"></a>

v-if

<span v-if="isOK" v-text="msg"></span>

绑定一个boolean值,如果为true输出,如果为false则不输出

v-show

<span v-show="isOK" v-text="msg"></span>

绑定一个boolean值,如果为true显示,如果为false则不显示display:none

v-for

遍历

//第一种写法<ul>
    <li v-for="item in names">
        {{item}}        <span v-text="item"></span>
    </li></ul>//第二种写法 设置唯一标示<ul>
    <li v-for="(item,index) in names" :key="index">
        {{index}} {{item}}        <span v-text="item"></span>
    </li></ul>//第三种写法 遍历对象   :key="item.id"<ul>
    <li v-for="(item,key,index) in user" :key="index">
        {{index}} {{key}} {{item}}    </li></ul>

v-on

//注册事件<button v-on:click="btnClick"> 显示或隐藏 </button>//简写<button @click="btnClick"> 显示或隐藏 </button>
//script中添加执行的方法
    export default {
        data() {            return {                msg: '<b>Hello Vue</b>',                tip: '这是一个提示',                isOK: false
            }
        },        methods: {
            btnClick() {                this.isOK = !this.isOK;
            }
        }
    }

指令的两个缩写

v-on:click --> @click
v-bind:id  --> :id

组件

  • 子组件的基本使用

//注意:component中的data要返回functionVue.component('my-item', {
    data() {        return {            count: 0
        }
    },    template: '<li @click="count += 1">{{count}}</li>'})var app = new Vue({    el: '#app',    data: {        msg: 'world'
    }
})
  • 控制组件的范围(父组件给子组件传值)

<my-item v-bind:test="msg"></my-item>var app = new Vue({
    el: '#app',
    data: {
        msg: 'hello'
    },
    components: {        'my-item': {
            props: ['test'],
            template: '<p>{{test}}</p>'
        }
    }
});
  • 子组件通知父组件

<my-item :count="count" @increate="increateDemo"></my-item>
Vue.component('my-item', {
    data() {        return {}
    },
    props: ['count'],
    template: '<div @click="divClick" >count: {{count}}</div>',
    methods: {
        divClick() {
            this.$emit('increate', '子组件传来的值');
        }
    }
})var app = new Vue({
    el: '#app',
    data: {
        count: 0
    },
    methods: {
        increateDemo(c) {
            console.log(c);
        }
    }

});
  • 加载.vue的子组件(需要配置好webpack)

      import App from './07-vue.vue' //加载.vue组件
    
      new Vue({      el: '#app', //将组件中的内容插入到页面中指定的元素
          render: c => c(App) //编译app.vue组件
      })

过滤器

  • 私有过滤器

<div id="app">
    <span>
      {{msg | toLower | replace('l','x')}}    </span>
  </div>
  <script>
    var app = new Vue({      el: '#app',      data: {        msg: 'Hello Vue'
      },      filters: {         toLower: function(input) {          return input.toLowerCase();
        },        replace: function(input, old, newValue) {          var r = new RegExp(old, 'g');          return input.replace(r, newValue);
        }
      }
    })  </script>
  • 全局过滤器

<div id="app">
    <span>
      {{msg | toLower | replace('l','n')}}    </span>
  </div>
  <script>
    Vue.filter('toLower', function(input) {      return input.toLowerCase();
    })

    Vue.filter('replace', function(input, old, newValue) {      var r = new RegExp(old, 'g');      return input.replace(r, newValue);
    })    var app = new Vue({      el: '#app',      data: {        msg: 'Hello Vue'
      }
    })

路由

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消