美文网首页
Vue 基础02

Vue 基础02

作者: 好久不见_3217 | 来源:发表于2018-09-13 15:24 被阅读0次

1.Vue

1.Vue (国内) Angular(国外) React(国外)前端流行语言框架
vue最容易学习,为轻量级语言,它的创始人是尤雨溪(华人)
vue操作元素更方便,简化了DOM操作

2.Vue指令

v-for="val /value(值) in arr "用来循环数组、对象
v-model=" "双向数据绑定,用于表单元素
v-on: 事件名=“ ” v-on:click="函数名” 绑定事件

3.v-model

p中与input中输出的内容一致

<div id="itany">
    <p>{{msg}}</p>
    <input type="text" v-model="msg">
</div>
<script src="../js/vue.js"></script>
<script>
    new Vue({
        el:"#itany",
        data:{
            msg:"hello"
        }
    })
</script>

4.v-on

<div id="itany">
    <p>{{msg}}</p>
    <button v-on:click="alt">点击</button>
</div>
<script src="../js/vue.js"></script>
<script>
    var vm=new Vue({
        el:"#itany",
        data:{
            msg:"hello"
        },
         methods:{
             alt:function(){
                 //alert(000)
                console.log(this.msg)
                 //console.log(vm.msg)
             }
         }
    })
</script>

5.点击切换文字

只能切换一次

<div id="itany">
    <p>{{msg}}</p>
    <button v-on:click="alt">点击</button>
</div>
<script src="../js/vue.js"></script>
<script>
    new  Vue({
        el:"#itany",
        data:{
            msg:"hello",
            txt:"hello,vue"
        },
        methods:{
            alt:function(){
                //this.msg="hello,vue"
                this.msg=this.txt
            }
        }
    })
</script>

6.点击来回切换文字

<div id="itany">
    <p>{{msg}}</p>
    <button v-on:click="alt">点击</button>
</div>
<script src="../js/vue.js"></script>
<script>
    new  Vue({
        el:"#itany",
        data:{
            msg:"hello",
            flag:true

        },
        methods:{
            alt:function(){
                //this.msg="hello,vue"
                //this.msg=this.txt
                if(this.flag){
                    this.msg="hello,vue"
                    this.flag=false
                }else {
                    this.msg="hello"
                    this.flag=true
                }
            }
        }
    })
</script>

7.添加删除

<div id="itany">
    <input type="text" v-model="msg">
    <button v-on:click="add">添加</button>
    <ul>
        <li v-for="(val,index) in arr">
            {{val}}
            <button v-on:click="delt(index)">删除</button>
        </li>
    </ul>
</div>
<script src="../js/vue.js"></script>
<script>
    new Vue({
        el:"#itany",
        data:{

           arr:["吃饭","睡觉","打游戏"],
            msg:""
        },
        methods:{
            add:function(){
                this.arr.push(this.msg)
                this.msg=""
            },
            delt:function(ind){
                this.arr.splice(ind,1);
            }

        }
    })
</script>

效果如图所示:

Image 1.png

相关文章

  • vue2 基础学习02 (Vue组件)

    vue2 基础学习02 (Vue组件) vue学习路径和建议----尤雨溪 vue官网 1.Vue组件 参考官方文...

  • Vue 基础-02-重点

    Vue 基础-day02-重点 01-基础-系统指令-v-bind-绑定 class-对象语法 :class="{...

  • Vue 基础02

    1.Vue 1.Vue (国内) Angular(国外) React(国外)前端流行语言框架vue最容易学习,为...

  • Vue基础-02

    1.计算属性 2.组件 创建组件法一:组件的创建和注册:①创建组件构造器②注册组件③挂载作用域下实例化组件 全局组...

  • 初识 Vue

    vue 是什么 vue 基础用法

  • 最新web前端相关课程学习链接

    js基础篇 js进阶篇 js高级篇 vue基础篇 vue高级篇 react基础 react高级 Nodejs基础 ...

  • Vue.js 第一课

    01. Vue.JS 第一课 02:51 Vue 1.0.21 Sublime Text 1 、vue: 读音: ...

  • 02-vue.js基础-Vue实例

    1.vue实例 每个 Vue 应用都是通过用 Vue 函数创建一个新的 Vue 实例开始的 2.数据和方法 当一个...

  • Vue基础-day02

    computed 计算属性出现的目的是解决模板中存放过多的逻辑会让模板过重且难以维护的问题 计算属性的基于他们的依...

  • 02、Vue-基础学习

    一、模版指令 通过模版指令(写在html中的),即是html和vue对象的粘合剂。 数据渲染 v-text、v-h...

网友评论

      本文标题:Vue 基础02

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