AI取名大师 | uni-app 微信小程序打包 v-bind、component 动态组件问题

关于 AI 取名大师

借助豆包通义千问DeepSeek 等 AI 大模型,为您的宝宝、宠物、店铺、网名、笔名、项目、产品、服务、文章等取一个专业、有意义的名字😄。


开源地址:👉GitCode(国内友好)👈、👉GitHub👈

技术组合:Bun.jsElysia.jsuni-app

体验地址:AI取名大师(H5版)

特别注明:本系列文章仅为实战经验分享,并记录开发过程中碰到的问题😄,如有不足之处欢迎随时留言提出。


v-bind / 属性绑定

直接上代码:

html 复制代码
<template>
	<view :title />
</template>

<script setup>
	let title = "标题"
</script>

这是一个再简单不过的 Vue3 示例,使用了绑定属性缩写,非常简洁清爽!编译为 h5 完全没问题,但是编译成微信小程序就会报错:

shell 复制代码
正在编译中...
✗ Build failed in 1.02s
[vite:vue] v-bind is missing expression.

2  |      <view @click="create" class="inline">
3  |          <slot>
4  |              <wd-button :icon="icon" :size="size" :type>创建积分券</wd-button>
   |                                         ^^^^^
5  |          </slot>
6  |      </view>

简单说就是微信小程序环境下不支持绑定缩写😔,只能一个个修给出:title="title"的形式,心累。如果需要多端支持,写代码时就得注意。

component is not supported

原始代码:

html 复制代码
<template>
	<component :is='buildSVG(bean)' />
</template>

<script setup>
	const buildSVG = item=>{
        let { color, svg, fill } = item.icon || {}
        if(svg && svg.startsWith("<svg "))
            return h('view', {class:"icon", innerHTML: svg })

        return h(
            item.id == 'baobao'? BabySVG:
            item.id == 'dianpu'? ShopSVG:
            item.id == 'chongwu'? DogSVG:
            item.id == 'wangming'? VestSVG:
            item.id == 'biming'? EditSVG:
            item.id == 'zuopin'? CreationSVG:
            item.id == 'wenzhang'? TitleSVG:
            null,
            { clazz:'icon', fill: fill || color, size: props.iconSize }
        )
    }
</script>

由于·微信小程序·的自定义组件系统不支持 <component is="">,也不支持 Vue 的动态组件渲染。

所以只能改成条件判断。

html 复制代码
<template>
    <template v-if="inited">
        <view v-if="custom" class="icon" :innerHTML="bean.icon.svg" />
        <BabySVG v-if="bean.id=='baobao'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <ShopSVG v-else-if="bean.id=='dianpu'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <DogSVG v-else-if="bean.id=='chongwu'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <VestSVG v-else-if="bean.id=='wangming'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <EditSVG v-else-if="bean.id=='biming'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <CreationSVG v-else-if="bean.id=='zuopin'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <TitleSVG v-else-if="bean.id=='wenzhang'" :fill="fill" :color="color" :size="size" clazz='icon' />
        <view v-else />
    </template>
</template>

<script setup>
    import BabySVG from '@SVG/baby.vue'
    import ShopSVG from '@SVG/shop.vue'
    import DogSVG from '@SVG/dog.vue'
    import EditSVG from '@SVG/edit.vue'
    import CreationSVG from '@SVG/creation.vue'
    import VestSVG from '@SVG/vest.vue'
    import TitleSVG from '@SVG/title.vue'

    const props = defineProps({
        bean:{type:Object, default:{}},
        size:{type:Number, default:48}
    })

    let inited = ref(false)
    let fill
    let color
    let custom = false

    onMounted(() => {
        let { svg } = props.bean.icon || {}
        if(svg && svg.startsWith("<svg "))
            custom = true

        fill = props.bean.icon?.fill
        color = props.bean.icon?.color

        inited.value = true
    })
</script>

Invalid pattern

shell 复制代码
Invalid pattern "../node-modules/wot-design-uni/components/wd-navbar/wd-navbar.js" for "output.chunkFileNames", patterns can be neither absolute nor relative paths. If you want your files to be stored in a subdirectory, write its name without a leading slash like this: subdirectory/pattern.

原因不明,删除 node_modules后,重新bun i就能正常打包😔。

相关推荐
小霖家的混江龙2 小时前
AI 为啥能回答你的问题?大模型 5 步工作流程,看完秒懂!
人工智能·llm
磊磊落落2 小时前
如何使用 Spec Kit 工具进行规范驱动开发?
人工智能
GoldenSpider.AI3 小时前
AI对话到视频的零编辑革命:NotebookLM与Lemon Slice的深度整合与未来洞察
人工智能·notebooklm·nanobanana·aivideo·lemon slice
草莓熊Lotso3 小时前
C++ STL set 系列完全指南:从底层原理、核心接口到实战场景
开发语言·c++·人工智能·经验分享·网络协议·算法·dubbo
大千AI助手5 小时前
代价复杂度剪枝(CCP)详解:原理、实现与应用
人工智能·决策树·机器学习·剪枝·大千ai助手·代价复杂度剪枝·ccp
zl_vslam6 小时前
SLAM中的非线性优-3D图优化之李群李代数在Opencv-PNP中的应用(四)
人工智能·opencv·算法·计算机视觉
whaosoft-1436 小时前
51c视觉~3D~合集8
人工智能
澳鹏Appen8 小时前
数据集月度精选 | 高质量具身智能数据集:打开机器人“感知-决策-动作”闭环的钥匙
人工智能·机器人·具身智能
q***710110 小时前
开源模型应用落地-工具使用篇-Spring AI-Function Call(八)
人工智能·spring·开源