1. 优化了一些交互,中药药品编辑交互
2. dev和生产环境统一鉴别
This commit is contained in:
23
utils/wxListKey.js
Normal file
23
utils/wxListKey.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 微信小程序 v-for :key 仅支持简单属性访问,不支持模板表达式。
|
||||
* 在 JS 中为列表项预生成 _wxKey 后,模板使用 :key="item._wxKey"
|
||||
*/
|
||||
export function withWxKey(list, idField = 'id', fallbackPrefix = 'i') {
|
||||
return (list || []).map((item, index) => ({
|
||||
...item,
|
||||
_wxKey: item[idField] != null && item[idField] !== ''
|
||||
? String(item[idField])
|
||||
: `${fallbackPrefix}${index}`,
|
||||
}))
|
||||
}
|
||||
|
||||
/** 单条消息/列表项补全 _wxKey(用于 push、$set 等增量更新) */
|
||||
export function ensureWxKey(item, idField = 'id', fallback) {
|
||||
if (!item || typeof item !== 'object') return item
|
||||
if (item._wxKey != null && item._wxKey !== '') return item
|
||||
const id = item[idField]
|
||||
return {
|
||||
...item,
|
||||
_wxKey: id != null && id !== '' ? String(id) : String(fallback),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user