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>

 

转载于:https://www.cnblogs.com/shy1766IT/p/11099535.html

Logo

前往低代码交流专区

更多推荐