• 为vue添加公用方法,vue添加通用方法


    common.js

    var common =function() {
        return{
            f1:function(){
                        console.log("this is common f1().");
                },
            f2:function(){
                        console.log(" out vist f222222().");
                },
            // 小写转大写
            toUppercase:function(o,parName){
                            if(o && o[parName]){
                                o[parName] = o[parName].toUpperCase();
                            }
                        }
        }}();
    if(typeof(Vue)=="function")Vue.prototype.common=common;

    html页

    <html>
    <head>
    <meta charset="UTF-8">
    <script src="https://vuejs.org/js/vue.min.js"></script>
    <script src="common.js"></script>
    </head>
    <body>
    <div id="app">
    <br>username:<input type="text" @keyup="common.toUppercase(v1,'username')" v-model="username" >
    {{username}}
    <br>userobj:<input type="text" @keyup="common.toUppercase(userobj,'usernameEN')" v-model="userobj.usernameEN" >
    </div>
    
    </body>
    </html>
    <script>
    var v1=new Vue({
      el: '#app',
      data: {
        username:"",
        userobj:{usernameEN:""}
        },
      created:function(){
            this.common.f1();
      }
        ,methods:{
            testf2:function(){
            //this.common.f2();
            }
        }
    })
    
    
    //在vue外面也可以调用
    common.f1();
    common.f2();
    </script>
  • 相关阅读:
    robotframework----模板的使用
    RF执行顺序
    RobotFrameWork(四)变量运算与Evaluate
    RobotFrameWork(三)数据类型
    git 命令
    常用网站
    git 应用
    ie if判断
    移动端rem适配
    绘制三角形(sass)
  • 原文地址:https://www.cnblogs.com/q149072205/p/10791117.html
Copyright © 2020-2023  润新知