Vue.js(2.0) 笔记

vue初识,模板语法

//除去启动时提示

  Vue.config.productionTip = false;
 var app=new Vue({

            //绑定方式1

            // el:'#app',

            //data{}对象式

            // data:{

            //  message:'hello hx',

            //  pp:'huang'

            // }

            //data(){}函数式

            data(){

                return{

                    message:'hello hx',

                    pp:'huang'

                }

            }

        })

        //绑定方式2

        app.$mount("#app")
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box1{
        font-size: 40px;
    }
</style>
<body>
    <div class="hx">
        <!-- 拼接 -->
        {{a+b+c}}
        <!-- 运算 -->
        {{d+e}}
        <!-- 判断 -->
        {{d>5?1:2}}
        <!-- 函数 -->
        {{f(99)}}
        <a href="http://www.baidu.com">百度官网</a>
        <!-- 动态v-bind:绑定href和class -->
        <a v-bind:href="aaa" v-bind:class="ss">我爱{{name}}</a>
    </div>
</body>
<script src="../vue.js代码/vue.js"></script>
<script>
    Vue.config.productionTip = false;
    //var的名字随意
    new Vue({
        el:".hx",
        data:{
            a:"i",
            b:"love",
            c:"you",
            d:520,
            e:1314,
            ss:"box1",
            name:"你",
            aaa:"http://www.baidu.com",
            f(e){
                return(e)
            }
        }
    })
</script>
</html>

methods处理函数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box2{
        font-size: 40px;
        color: antiquewhite;
    }
    .box3{
        font-size: 20px;
        color: aqua;
    }
</style>
<body>
    <div id="app">
        <button v-on:click="func1()">点击1</button>
        <button v-on:click="func2()">点击2</button>
        <h1 v-bind:clsss="hx">我现在点击的是{{num}}</h1>
        <h1 :class="hx">事件</h1>
        <h2 :style="boss[1]">绑定样式</h2>
    </div>
</body>
<script src="../vue.js代码/vue.js"></script>
<script>
     Vue.config.productionTip = false;
    new Vue({
        el:"#app",
        data(){
            return{
                num:"",
                hx:"",
                //写法1
                // boss:{
                //     border:"2px solid red",
                //     textAlign:"center"
                // }
                //写法2
                boss:[
                    {
                        border:"2px solid red",
                        textAlign:"center"
                    },
                    {
                        border:"3px solid green",
                    }
                ]
            }
        },
        methods:{
            func1:function(){
                this.num=1;
                console.log(22222);
                this.hx="box2"
            },
            func2:function(){
                this.num=2;
                console.log(33333);
                this.hx="box3"
            },
        },
    })
</script>
</html>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值