绑定元素名称

绑定元素名称使用v-bind:属性名 == :属性名

绑定事件
v-on:事件 == @事件
注:事件名称一定不要加on
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            font-size: 50px;
            color: red;
        }
        .box2{
            font-size: 30px;
            color: pink;
        }
    </style>
</head>
<body>
    <div id="app">
        {{userName}}----{{this.userName}}
        <!-- 绑定元素名称使用v-bind:属性名 == :属性名 -->
        <a v-bind:href="http">访问链接</a>
        <a :href="https">访问链接</a>
        <h1>{{func()}}</h1>
        <!-- 绑定事件
        v-on:事件 == @事件 
        注:事件名称一定不要加on-->
        <button v-on:click="func1(1)">点击1</button>
        <button @click="func1(2)">点击2</button>
        <h1 :class="sty">我现在点击的是{{num}}</h1>
        <h1 :style="boss[0]">绑定样式style</h1>
    </div>
</body>
<script src="../vue.js"></script>
<script>
    Vue.config.productionTip = false;
    var userName = "李四";
    var vm = new Vue({
        // el:"#app",
        data(){
            return{
                userName:"张三",
                http:"http://www.baidu.com",
                https:"https://v2.cn.vuejs.org/v2/api/#methods",
                num:"",
                sty:"",
                // boss:"border:5px solid orange;color:green;"
                // boss:{
                //     border:"5px solid orange",
                //     color:"pink",
                //     // textAlign:"center"
                //     "text-align":"right"
                // }
                boss:[
                    {
                        border:"5px solid pink"
                    },
                    {
                        color:"red"
                    }
                ]
            }
        },
        // methods处理的函数方法
        methods: {
            func(){
                console.log(1111111);
                return 1111111;
            },
            func1:function(user){
                if(user==1){
                    this.num = 1;
                    this.sty = "box1";
                    console.log(222222222);
                }else {
                    this.num = 2;
                    this.sty = "box2"
                    console.log(333333333);
                }
            },
            // func1:()=>{
            //     console.log(111111111);
            //     console.log(this);
            //     console.log(this.userName);
                // this.num = 1;
                // this.sty = "box1";
                // console.log(222222222);
            // },
            func2(){
                this.num = 2;
                this.sty = "box2"
                console.log(333333333);
            }
        },
    })
    vm.$mount("#app");
</script>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值