zoukankan      html  css  js  c++  java
  • vue基本指令2

    1.v-if条件渲染

    <div v-if="flags">ok</div>
    <div v-else>no</div>

    <script>
    export default {
    name: 'HelloWorld',
    data() {
    return {
    msg: 'Welcome to Your Vue.js App',
    biaoqian: "<h1>我是H1标签</h1>",
    url_name: "百度",
    url: "https://www.baidu.com",
    disClass: "disactive",
    dis2Class: "item",
    flags: false
    }
    }
    }
    </script>

    2.v-show

    <div v-show="showFun">show</div>

    <script>
    export default {
    name: 'HelloWorld',
    data() {
    return {
    msg: 'Welcome to Your Vue.js App',
    biaoqian: "<h1>我是H1标签</h1>",
    url_name: "百度",
    url: "https://www.baidu.com",
    disClass: "disactive",
    dis2Class: "item",
    flags: false,
    showFun:false
    }
    }
    }
    </script>

    3.列表渲染v-for

    <div v-for="person in persons">{{person}}</div>

    <ul><li v-for="item in personz">{{item.name}}--{{item.age}}</li></ul>

    <ul><li v-for="(item,key,index) in personz" :key="index">{{index}}-{{item.name}}--{{item.age}}--{{key}}</li></ul>

    <script>
    export default {
    name: 'HelloWorld',
    data() {
    return {
    msg: 'Welcome to Your Vue.js App',
    biaoqian: "<h1>我是H1标签</h1>",
    url_name: "百度",
    url: "https://www.baidu.com",
    disClass: "disactive",
    dis2Class: "item",
    flags: false,
    showFun:false,
    persons:[
    "小明明",
    "小医仙",
    "小菲菲"
    ],
    personz:[
    {"name":"小明明","age":20},
    {"name":"小明明","age":10},
    {"name":"小明明","age":100}
    ]
    }
    }
    }
    </script>

    4.事件处理(事件改变datas数据,data数据的变化引起视图的变化)

    事件传递参数$event

    <button class="" type="button" @click="clickHandler('hahha',$event)">按钮</button>

    <script>
    export default {
    name: 'HelloWorld',
    data() {
    return {
    msg: 'Welcome to Your Vue.js App',
    biaoqian: "<h1>我是H1标签</h1>",
    url_name: "百度",
    url: "https://www.baidu.com",
    disClass: "disactive",
    dis2Class: "item",
    flags: false,
    showFun: false,
    persons: [
    "小明明",
    "小医仙",
    "小菲菲"
    ]

    }
    },
    methods: {
    clickHandler(data,$event) {

    console.log(data)

    console.log($event)

    this.flags =!this.flags
    /* if(this.flags==true){
    this.flags=false
    } */
    }
    }
    }
    </script>

    5.数组 的更新检测

    变异方法

    改变原数组,则可以引起视图的更新(push;unshift)

    不改变原数组,创建新数组,则无法引起视图的更新(concat,slice,filter)

    <ul class="list"><li v-for="item in fruits">{{item}}</li></ul>
    <button @click="newadds($event)">addto</button>

    <script>
    export default {
    name: 'HelloWorld',
    data() {
    return {
    msg: 'Welcome to Your Vue.js App',
    biaoqian: "<h1>我是H1标签</h1>",
    url_name: "百度",
    url: "https://www.baidu.com",
    disClass: "disactive",
    dis2Class: "item",
    flags: false,
    showFun: false,
    persons: [
    "小明明",
    "小医仙",
    "小菲菲"
    ],
    fruits:[
    "bananas",
    "apple",
    "pears"
    ]

    }
    },
    methods: {
    clickHandler(data,$event) {
    console.log(data)
    console.log($event)
    this.flags =!this.flags
    /* if(this.flags==true){
    this.flags=false
    } */
    },
    newadds(){
    // this.fruits.push("applebig");
    //this.fruits.unshift("applesmall");
    this.fruits.concat("applesmall");
    console.log(this.fruits.concat("applesmall"))
    }
    }
    }
    </script>

  • 相关阅读:
    洛谷P1527 矩阵乘法——二维树状数组+整体二分
    bzoj1503 [NOI2004]郁闷的出纳员——splay
    bzoj4811 [Ynoi2017]由乃的OJ 树链剖分+位运算
    D Dandan's lunch
    C Sleepy Kaguya
    B bearBaby loves sleeping
    A AFei Loves Magic
    II play with GG
    angular的路由和监听路由的变化和用户超时的监听
    ng-disabled 指令
  • 原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11300291.html
Copyright © 2011-2022 走看看