当前位置 : 主页 > 网页制作 > html >

三 .web框架-----------VUE使用(三)

来源:互联网 收集:自由互联 发布时间:2021-06-12
一 .VUE使用 https://cn.vuejs.org/v2/guide/routing.html 1.Vue成员获取(挂载) !DOCTYPE htmlhtml lang="en"head meta charset="UTF-8" title智能社——http: // www.zhinengshe.com/title style /style script src="vue.js"/script script /s

一 .VUE使用   https://cn.vuejs.org/v2/guide/routing.html

1.Vue成员获取(挂载)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
  
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        {{a}}
    </div>
    <script>
        //vm.$el -> 就是元素
        var vm=new Vue({
          el:‘#box‘,
            data:{
                a:1
            }
        });

        //alert(vm.$el);
        vm.$el.style.background=‘red‘;
    </script>
</body>
</html>
分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        {{a}}
    </div>
    <script>
// vm.$data -> 就是data
        var vm=new Vue({
            el:‘#box‘,
            data:{
                a:1
            }
        });

        console.log(vm.$data.a);
    </script>
</body>
</html>
分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        <span v-text="a"></span>
    </div>
    <script>
//      vm.$mount ->  手动挂在vue程序
        //angular.bootstrap
        /*var vm=new Vue({
            data:{
                a:1
            }
        });

 vm.$mount(‘#box‘); //手动挂载*/

        var vm=new Vue({
            data:{
                a:1
            }
        }).$mount(‘#box‘);
    </script>
</body>
</html>
分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        <span v-text="a"></span>
        <br>
        {{aa}}
    </div>
    <script>
//vm.$options -> 获取自定义属性
        var vm=new Vue({
            aa:114444, //自定义属性,
            show:function(){
                
                alert(1);
                
            },
            data:{
                a:"vm.$options    ->   获取自定义属性"
            }
        }).$mount(‘#box‘);

        vm.$options.show();
        
        console.log(vm.$options.aa);
    </script>
</body>
</html>
分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        <span v-text="a"></span>
    </div>
    <script>
// vm.$log();    ->  查看现在数据的状态
        var vm=new Vue({
            data:{
                a:33333333,
                b:44444444444
            }
        }).$mount(‘#box‘);

        console.log(vm.$log());
    </script>
</body>
</html>
分享图片

 2. 计算属性computed

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        a => {{a}}
        <br>
        b => {{b}}
    </div>
    <script>
        //* computed里面可以放置一些业务逻辑代码,一定记得return
        var vm=new Vue({
            el:‘#box‘,
            data:{
                a:1
            },
            computed:{
                b:function(){
                    //业务逻辑代码
                    return 2;
                }
            }
        });
        console.log(vm.a);
    </script>
</body>
</html>
分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        a => {{a}}
        <br>
        b => {{b}}
    </div>
    <script>
            //* computed里面可以放置一些业务逻辑代码,一定记得return
        vax‘,
            datar vm=new Vue({
            el:#box:{
                a:1
            },
            computed:{
                b:function(){
                    //业务逻辑代码
                    return this.a+1;
                }
            }
        });

        document.onclick=function(){
            vm.a=101;
        };
    </script>
</body>
</html>
分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style>

    </style>
    <script src="vue.js"></script>
    <script>

    </script>
</head>
<body>
    <div id="box">
        a => {{a}}
        <br>
        b => {{b}}
    </div>
    <script>
            //* computed里面可以放置一些业务逻辑代码,一定记得return
        var vm=new Vue({
            el:‘#box‘,
            data:{
                a:1
            },
            computed:{
                b:{
                    get:function(){
                        return this.a+2;
                    },
                    set:function(val){
                        this.a=val;
                    }
                }
            }
        });

        document.onclick=function(){
            vm.b=45;
        };
    </script>
</body>
</html>
分享图片  分享图片
上一篇:TP5 pc和wap跳转404
下一篇:初步了解HTML
网友评论