8***@qq.com
8***@qq.com
  • 发布:2025-05-14 11:06
  • 更新:2025-05-15 15:26
  • 阅读:56

【报Bug】input keyboard-accessory编译后嵌套关系问题

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 11

HBuilderX类型: 正式

HBuilderX版本号: 4.65

第三方开发者工具版本号: 1.03.2412050

基础库版本号: 3.8.3

项目创建方式: HBuilderX

示例代码:

运行或者发行下面代码

<input  class="hidden-input" hold-keyboard  type="digit" >    
        <keyboard-accessory>    
                <cover-view class="custom__list">    
                        <cover-view class="custom__item" v-for="i in 4" :key="i" @click="change(i)">{{i * 5}}</cover-view>    
                </cover-view>    
        </keyboard-accessory>    
    </input>

编译出来最终结果如下, 嵌套关系不存在了

<input  class="hidden-input" hold-keyboard  type="digit" />    
<keyboard-accessory>    
                <cover-view class="custom__list">    
                        <cover-view class="custom__item" v-for="i in 4" :key="i" @click="change(i)">{{i * 5}}</cover-view>    
                </cover-view>    
</keyboard-accessory>

操作步骤:

<input class="hidden-input" hold-keyboard type="digit" >
<keyboard-accessory>
<cover-view class="customlist">
<cover-view class="custom
item" v-for="i in 4" :key="i" @click="change(i)">{{i * 5}}</cover-view>
</cover-view>
</keyboard-accessory>
</input>

预期结果:

<input class="hidden-input" hold-keyboard type="digit" >
<keyboard-accessory>
<cover-view class="customlist">
<cover-view class="custom
item" v-for="i in 4" :key="i" @click="change(i)">{{i * 5}}</cover-view>
</cover-view>
</keyboard-accessory>
</input>

实际结果:

<input class="hidden-input" hold-keyboard type="digit" />
<keyboard-accessory>
<cover-view class="customlist">
<cover-view class="custom
item" v-for="i in 4" :key="i" @click="change(i)">{{i * 5}}</cover-view>
</cover-view>
</keyboard-accessory>

bug描述:

使用HBuildeX 运行或者发行, 解析input嵌套关系错误

2025-05-14 11:06 负责人:无 分享
已邀请:
DCloud_UNI_JBB

DCloud_UNI_JBB

临时解决方案

替换 /Applications/HBuilderX/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-mp-compiler/dist/parserOptions.js 为 下面的代码

注意不能这样 <input type="text"> 否则会编译失败

"use strict";  
Object.defineProperty(exports, "__esModule", { value: true });  
exports.parserOptions = void 0;  
const compiler_core_1 = require("@vue/compiler-core");  
const shared_1 = require("@vue/shared");  
exports.parserOptions = {  
    isVoidTag(tag) {  
        if (tag === 'input') {  
          return false  
        }  
        return (0, shared_1.isVoidTag)(tag);  
    },  
    isNativeTag: (tag) => (0, shared_1.isHTMLTag)(tag) || (0, shared_1.isSVGTag)(tag),  
    isPreTag: (tag) => tag === 'pre',  
    // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher  
    getNamespace(tag, parent) {  
        let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;  
        if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {  
            if (parent.tag === 'annotation-xml') {  
                if (tag === 'svg') {  
                    return 1 /* DOMNamespaces.SVG */;  
                }  
                if (parent.props.some((a) => a.type === compiler_core_1.NodeTypes.ATTRIBUTE &&  
                    a.name === 'encoding' &&  
                    a.value != null &&  
                    (a.value.content === 'text/html' ||  
                        a.value.content === 'application/xhtml+xml'))) {  
                    ns = 0 /* DOMNamespaces.HTML */;  
                }  
            }  
            else if (/^m(?:[ions]|text)$/.test(parent.tag) &&  
                tag !== 'mglyph' &&  
                tag !== 'malignmark') {  
                ns = 0 /* DOMNamespaces.HTML */;  
            }  
        }  
        else if (parent && ns === 1 /* DOMNamespaces.SVG */) {  
            if (parent.tag === 'foreignObject' ||  
                parent.tag === 'desc' ||  
                parent.tag === 'title') {  
                ns = 0 /* DOMNamespaces.HTML */;  
            }  
        }  
        if (ns === 0 /* DOMNamespaces.HTML */) {  
            if (tag === 'svg') {  
                return 1 /* DOMNamespaces.SVG */;  
            }  
            if (tag === 'math') {  
                return 2 /* DOMNamespaces.MATH_ML */;  
            }  
        }  
        return ns;  
    },  
    parseMode: 'html',  
};

要回复问题请先登录注册