codecamp

MorJS Mock 如何使用 Adapter

每个 adapter 支持 string 类型和 array 两种类型:

  • string 类型,参数为本地 adapter 路径或 npm 包名,配置以加载该 adapter
export default defineConfig([
  {
    name: 'ali',
    sourceType: 'alipay' ,
    target: 'alipay',
    ...,
    mock: {
      ...,
      adapters: [
        './you_adapter_name.js', // string 类型本地 adapter 文件路径
      ],
    }
  },
])
  • array 类型,接收两个参数,加载 adapter 并向其传参
    • 第一个参数为本地 adapter 路径或 npm 包名
    • 第二个参数为传给 adapter 的参数(非必填)
import { defineConfig } from '@morjs/cli'

export default defineConfig([
  {
    name: 'ali',
    sourceType: 'alipay' ,
    target: 'alipay',
    ...,
    mock: {
      ...,
      adapters: [
        [
          // 参数①: 本地 adapter 或 npm 包名
          'your_adapter_name',
          // 参数②: 提供 adapter 的参数
          {
            type: 'your_parameter_type',
            api: 'your_parameter_api'
          }
        ],
      ],
    }
  },
])


MorJS Mock mock 配置
MorJS Mock 如何编写 Adapter
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

MorJS 指南

MorJS 基础用法

MorJS 配置

MorJS 编译相关配置

MorJS 进阶用法

MorJS Web开发

MorJS Web开发介绍

MorJS Web开发快速上手

MorJS Tabbar IOS 小黑条适配开关

MorJS 社区

MorJS 规范

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }