微信小程序字符串拼接,实现SetData对变量名赋值

1、直接对串进行拼接
  如 app.globalData.server_url=“https://image.baidu.com/",action='search'
  let url0 = `${app.globalData.server_url}${action}`;
  则 url0=‘https://image.baidu.com/search'
2、实现SetData对变量名赋值
  如:let para1=’name‘,value1='马大哈'
  this.setData({
    [`${para1}`]: value1
  })
  则实现了对name的赋值,等同于:
  this.setData({
    name:'马大哈'
  })
posted @ 2023-01-24 11:47  淡定=淡定  阅读(1378)  评论(0)    收藏  举报