zoukankan      html  css  js  c++  java
  • vue设置公共常量

    Global.vue

    <template>
    </template>
    <script type="text/javascript">
    const pay_model =[
        { state: '1',type:'现金'},
         { state: '2',type:'支付宝'},
         { state: '3',type:'微信'},
    ],
    const yuyue = [
         { state: '1',type:''},
         { state: '2',type:'不是'},
         { state: '0',type:'未知'},
    ]
    function getStateName (state, arr) {
      for(var i = 0;i<arr.length;i++){
        if(arr[i].state === state){
          return arr[i].type
        }
      }
    }
    export default{
      pay_model ,
      yuyue ,
      getStateName
    }
    </script>
    <style>
    </style>

    使用就和组件使用方式一样

    <template>
        <div>
            <ul>
                <li v-for='item in lis'>{{item.type}}</li>
            </ui>
            <span>{{content}}</span>
        </div>
    </template>
    <script>
    import global_   from  './Global.vue'
    export default{
        data(){
            return {
              lis :global_.pay_model,
              content: ''
            }
        },
        created(){
            var c = 1
             this.content = global_.getStateName(c,global_.pay_model)
        }
    }
    </script>
  • 相关阅读:
    1、Python的初识与简介
    解密解密
    python看是32位还是64
    linux实战一段,安装python3(centos)
    前段技巧
    django后端safe和前端safe的方法
    测试
    python小知识整理
    ajax格式
    111
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/11099535.html
Copyright © 2011-2022 走看看