代码优化示例

// 这种写法不仅繁琐,而且会导致form中的input无法正常输入文字
async getPrinterScheme(info) {
      const { printerId, shopId, erpModel, id: useSceneId, isCloudPrinter } = info
      const { data } = await this.axios.post(`/printScheme/${printerId}/${shopId}/${erpModel}/${useSceneId}/${isCloudPrinter}/getPrinterScheme`)
      this.ruleForm = data.data || {}
      if (!this.ruleForm.printMachine) {
        this.ruleForm.printMachine = 0
      }
      if (!this.ruleForm.printNumber) {
        this.ruleForm.printNumber = 1
      }
      if (!this.ruleForm.leftPadding) {
        this.ruleForm.leftPadding = 0
      }
      if (!this.ruleForm.rightPadding) {
        this.ruleForm.rightPadding = 0
      }
      this.printMachine = this.ruleForm.printMachine
      if (!this.ruleForm.printSchemeMachineList) {
        this.ruleForm.printSchemeMachineList = []
      }
    },
    async getPrinterScheme(info) {
      const { printerId, shopId, erpModel, id: useSceneId, isCloudPrinter } = info
      const { data } = await this.axios.post(`/printScheme/${printerId}/${shopId}/${erpModel}/${useSceneId}/${isCloudPrinter}/getPrinterScheme`)
      const theData = data.data || {}
      const { printMachine = 0, printNumber = 1, leftPadding = 0, rightPadding = 0, printSchemeMachineList = [] } = theData
      this.ruleForm.printMachine = printMachine
      this.ruleForm.printNumber = printNumber
      this.ruleForm.leftPadding = leftPadding
      this.ruleForm.rightPadding = rightPadding
      this.ruleForm.printSchemeMachineList = printSchemeMachineList
    },

iOS杂记

验证正式环境的远程推送是否正常

可以用Ad Hoc的分发方式,打包上传蒲公英,然后安装到手机。

解决xcode14.3打包失败的问题

前端杂记

微信小程序云开发实现关键词搜索

if (keyword) {
    param.title = db.RegExp({
      regexp: event.keyword,
      options: 'i',
    })
  }

将鼠标光标改成小手形状(意指可点击)

style="cursor: pointer;"

created与mounted的区别

created //通常用于初始化某些属性值,例如data中的数据,然后再渲染成视图。
mounted //通常在初始化页面完成后,对html的dom节点进行需要的操作。

el-input中监听键盘事件“回车”

<el-input @keyup.enter.native="login()" "></el-input>

input监听回车键

<input @keyup.enter="login()" />

全局忽略eslint的报错

在项目根目录创建文件.eslintignore
内容为src,保存即可

JavaScript中的filter()和includes()

数组a=[{"name":"张三","id":1},{"name":"李四","id":2},{"name":"王五","id":3}],
如何筛选出id为1和id为2的对象?

const a = [{"name":"张三","id":1},{"name":"李四","id":2},{"name":"王五","id":3}];

const filtered = a.filter(obj => [1, 2].includes(obj.id));

console.log(filtered); // [{"name":"张三","id":1},{"name":"李四","id":2}]

通过控制台命令行检测跨域

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://110.41.5.78:9999/df/pagePush");
xhr.send(null);
xhr.onload = function(e) {
    var xhr = e.target;
    console.log(xhr.responseText);
}

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://bar-bingo.deeptel.com.cn/sys/interact-setting/gift/page?pageIndex=1&pageSize=10");
xhr.send(null);
xhr.onload = function(e) {
    var xhr = e.target;
    console.log(xhr.responseText);
}

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://synthesize.deeptel.com.cn/overall/link/erp-model");
xhr.send(null);
xhr.onload = function(e) {
    var xhr = e.target;
    console.log(xhr.responseText);
}