Vue学习一

一、Vue环境安装

在Vue官网下载Vue.js或Vue.min.js引入,也可以用csdn

二、Vue实例

1、在js文件中或script标签中,new Vue({

    el:'#id',

    data:{

        name:'老王',

        message:"hello word",

        message2:"hello everyone"

        isgreen:true,

        error:null

    }

    methods:{//这是方法

           reverseName:function(){

                this.name = 

                alert("反转成功");

            }


        }

    computed:{//这是计算属性,

        computedTest:function(){

                return green:this.isgreen && !this.error,'text-danger':this.error&&this.error.type==fatal;

            }

    }

})


2、在Html标签中

1)、用v-bind绑定例如:

<div id="classtyletest">

    <div id="styletest" v-bind:class="styletestclass"></div>

</div>

2)、如果要输出html,用v-html例如<p v-html="htmlmessage"></p>,这就完成了html输出

new Vue({

el:'',

data:{

        htmlmessage:"<table>...</table>"

    }

})


3)、绑定事件用v-on,例如:v-on:click,v-ondblclick,v-on:mousemove,v-on:keyup,等,

有鼠标点击,双击事件,鼠标移动事件,键盘事件

4)、数组遍历用v-for,

<div id="ifandfor">
    <ol>
        <li v-for="lesson in lessons">{{lesson.lesson}}</li>
    </ol>
</div>

猜你喜欢

转载自blog.csdn.net/qq_38282454/article/details/80739197