有2种方案解决 1.将这些组件配置成页面,被编译了,自然就有占位符了 2.编译后,写一个脚本,给这些json文件添加占位符配置 我是使用方案2 ,将需要加配置的组件放到一个目录下面,然后写了一个插件,给这些json文件加配置 import path from 'path' import { readdir, readFile, writeFile, stat } from 'node:fs/promises' export default function FixComponentPlaceholderPlugin(options = {}) { const { dist = 'dist/build/mp-weixin', subDirs = [], recursive = true, placeholder = { 'com-chart': 'view' } } = options // 递归处理 JSON 文件 async function processDir(dirPath) { const entries = await readdir(dirPath, { withFileTypes: true }) for (const entry of entries) { const fullPath = path.join(dirPath, entry.name) if (entry.isDirectory() && recursive) { await processDir(fullPath) } if (entry.isFile() && entry.name.endsWith('.json')) { try { const jsonStr = await readFile(fullPath, 'utf-8') const json = JSON.parse(jsonStr) json.componentPlaceholder = { ...(json.componentPlaceholder || {}), ...placeholder } await writeFile(fullPath, JSON.stringify(json, null, 2), 'utf-8') // console.log(`✅ 修改成功: ${fullPath}`) } catch (e) { // console.warn(`❌ 处理失败: ${fullPath}`, e) } } } } return { name: 'vite-plugin-fix-component-placeholder', async closeBundle() { if (!subDirs.length) { console.warn('⚠️ 没有指定 subDirs,跳过处理') return } for (const subDir of subDirs) { const fullDir = path.resolve(process.cwd(), dist, subDir) try { const stats = await stat(fullDir) if (stats.isDirectory()) { await processDir(fullDir) } else { console.warn(`⚠️ 跳过:${fullDir} 不是一个目录`) } } catch (err) { console.warn(`⚠️ 目录不存在或无法访问:${fullDir}`) } } } } } [图片]
主包中某页面中的子组件如何配置componentPlaceholder去占位分包的组件?在主包home的组件member-box里去用分包pages-mine的一个组件member-pop,注意:是在主包home的组件里去用,不是注册到页面home 的pages的这个页面,而是在home的子组件member-box去使用 [图片] 在pages.json中配置了主包home,home页面的子组件member-box怎么配置componentPlaceholder占位符引用分包组件member-pop呢?? [图片] 会报错没找到占位符 [图片] [图片] 可以看出主包home的组件member-box确实没有配置componentPlaceholder占位符 如果在member- box.json页面手动加上componentPlaceholder,就不报错了 [图片] 问:如何在子组件如何配置componentPlaceholder去占位分包的组件,uniapp 中子组件不像原生的页面有.json,可以直接配置componentPlaceholder,uniapp写法如何配置子组件的占位符componentPlaceholder呢??
04-16分包异步化 可以跨分包使用组件,在使用页面加 "componentPlaceholder":{'组件名':'占位符'}
分包可以用其他分包的组件吗?[图片] pages/login/login这个页面,引用sub-shopping这个分包下面的组件,这样不可以吗,h5正常,微信小程序出错,是什么原因呢,要怎么改
04-16if (!formModel['key' + index]) { if (!formConfig[index].delete) formConfig[index].delete=0 formConfig[index].delete++ formModel['key' + index]=' ' if (index > 0 && formConfig[index].delete>1) { const prevIndex= findPrevIndex(index) focus_index.value = prevIndex formConfig[index].delete=0 } return } 我解决了,就是在值为空的时候赋值一个空串,后面删除时候就会触发input事件了,后面取值时候在trim()去除空串就行了
小程序删除键(backspace)怎么监听???小程序删除键(backspace)怎么监听??? bindinput键可以监听其他输入,但是删除键没有输入,bindchange键可以监听一开始有值的,但是一开始没有值怎么监听? 比如六个密码框,每输完一个框自动跳入下一个input框,但是此时点删除怎么删除上一个input框的内容??? 如下图: [图片]
2024-07-03