快应用中引入.json、.js类型的文件

956 阅读1分钟

快应用中引入.json文件

项目中静态资源一般是放在json里面,因为很多语言都支持json,通过import的方式引入

1、在 src/i18n 目录新增en.json文件中, 添加如下代码

  • en.json
{
  "name": "Epidemic prevention health code",
  "loadingMsg": "Loading",
  "bind": "To bind",
  "updateTime": "UpdateTime",
  "servicing": "Currently unavailable in server maintenance",
  "outdateLine": "Login expired!",
  "abnormal": "There is an exception",
  "noabnormal": "No abnormality seen",
  "noBindMes": "You are not identity bound in the National Government Platform fast application or binding expired."
}

  1. 引入
import en from '../i18n/en.json'

3.使用,某些代码会省略

 <text class="none-text">{{ en.servicing }}</text>
 <text class="none-text">{{ zh.servicing }}</text>
 
   private: {
    en,
    zh,
  },

快应用中引入.js文件(其一)

1、在 src/utils 目录新增utils.js文件中, 添加如下代码

// 深拷贝
export function deepCopy(obj) {
  if (typeof obj !== "object") {
    return;
  }
  const str = JSON.stringify(obj);
  return JSON.parse(str);
}

  1. 引入
import { deepCopy } from '../utils/util'

3.使用,某些代码会省略

import { deepCopy } from '../utils/util'
export default {
  accountNormalRegister() {
    const params = deepCopy(queryForm)

  },

}

快应用中引入.js文件(其二)

1、在 src/pages/home 目录新增data.js文件中, 添加如下代码

export default {
  label: "欢迎办理高考业务",
  listCollection: [
    {
      listData: [
        {
          name: "录取查询",
          uri: "views/Gaokao/Query?type=matriculate"
        }
      ]
    }
  ]
};

  1. 引入
import gaokao from './data.js'

3.使用,某些代码会省略

<script>
import gaokao from './data'
import { pageShow } from '../../utils/tracker'

export default {
  data() {
    return {
      label: gaokao.label,
      listCollection: gaokao.listCollection
    }
  },

}
</script>