最近搜索

一种全新的写法。学习的新的技巧。

浏览:49
管理员 2025-04-23 09:19




小程序 代码。更新数组某个节点的属性。

  update_ok(e){
    console.log(e.detail);//e.detail.client  e.detail.phone 
    const { index, client, phone, address, remark } = e.detail;
    this.setData({
      [`xiaoshouHeadList[${index}].client`]: client,
      [`xiaoshouHeadList[${index}].phone`]: phone,
      [`xiaoshouHeadList[${index}].address`]: address,
      [`xiaoshouHeadList[${index}].remark`]: remark,
      edit_show: false
    });
    
  }

image.png



some的应用  小程序  和js页面都可以用

   // 使用 some 检查是否有元素
    if (this.data.selectGoodsList.some(function (item) {
        //判断num是数字 不能是0 不能是负
        if (!isNum1(item.xiaoshou_num)) {
          wx.showToast({
            title: "第" + row_num + "行,请输入正确的数量",
            icon: 'none',
            duration: 2000
          })
          return true;
        }
        //判断 数字 或者浮点
        if (!isNum2(item.xiaoshou_price)) {
          wx.showToast({
            title: "第" + row_num + "行,请输入正确的单价",
            icon: 'none',
            duration: 2000
          })
          return true;
        }
        data.push({
          num: item.xiaoshou_num,
          goods_id: item.id,
          danjia: item.xiaoshou_price,
          zongjia: item.total,
        });
        row_num++;
      })) { // some 返回 true  相当于if判断是true  终止 执行return
      return; // 终止整个函数 fun 的执行
    }



字符串模板   还可以调用 方法  小程序 和js都可以用

let name = "Alice";  
let greeting = `Hello, ${name}! Welcome to our website.`;  
console.log(greeting);  // 输出: Hello, Alice! Welcome to our website.
 
 
function getGreeting(name) {
    return `Hello, ${name}!`;
}
let userName = "Alice";
let message = `Today, ${getGreeting(userName)} How are you?`;
console.log(message);  // 输出: Today, Hello, Alice! How are you?


小程序 调用 方法需要加this.getGreeting  需要加个this.


vue3 的一种写法。构建查询字符串  小程序不能用,没有URLSearchParams

 // 假设queryForm.value和token.value已经定义并且包含你需要的数据
 const params = {
   query: queryForm.value.query,
   pageNum: queryForm.value.pageNum,
   pageSize: queryForm.value.pageSize,
   deptId: queryForm.value.deptId,
   // 如果需要传递state,则取消下面的注释
    state: queryForm.value.state,
   token: token.value
 };
// 使用URLSearchParams来构建查询字符串
 const queryString = new URLSearchParams(params).toString();
// 现在你可以使用这个查询字符串来构建你的URL
 location.href = `${getServerUrl()}api/hit/down/excel?${queryString}`;



vue3 下拉菜单的内容 可以定义为常量。保存在js文件。方便修改和多个地方调用





const selectGoodsList = this.data.selectGoodsList;
    const statistics = selectGoodsList.reduce((acc, item) => {
      const num = parseFloat(item.pandianNum) || 0;
      return {
        totalNum: acc.totalNum + num
      };
    }, {
      totalNum: 0,
      totalPrice: 0
    }); // 初始值
    this.setData({
      totalNum: statistics.totalNum
    });


联系站长

站长微信:xiaomao0055

站长QQ:14496453