Skip to content

vue-template-compiler 解析 HTML 模板的边界问题 #10165

Closed
@cfour-hi

Description

@cfour-hi

Version

15.7.0

Reproduction link

https://codepen.io/Monine/pen/rELQZW

Steps to reproduce

视图会输出 render 属性值,打开开发者工具查看 console 面板也可以查看编译结果。

What is expected?

render 属性的值应该为:

"with(this){return _c('CustomerComp',{scopedSlots:_u([_l((['a']),function(name){return {key:name,fn:function(){return undefined},proxy:true}}),_l((['b']),function(name){return {key:name,fn:function(){return undefined},proxy:true}})],null,true)})}"

格式化后:

with (this) {
  return _c('CustomerComp', {
    scopedSlots: _u(
      [
        _l(['a'], function(name) {
          return {
            key: name,
            fn: function() {
              return undefined;
            },
            proxy: true,
          };
        }),
        _l(['b'], function(name) {
          return {
            key: name,
            fn: function() {
              return undefined;
            },
            proxy: true,
          };
        }),
      ],
      null,
      true,
    ),
  });
}

What is actually happening?

render 属性的值为:

"with(this){return _c('CustomerComp',{scopedSlots:_u([_l((['b']),function(name){return {key:name,fn:function(){return undefined},proxy:true}})],null,true)})}"

格式化后:

with (this) {
  return _c('CustomerComp', {
    scopedSlots: _u(
      [
        _l(['b'], function(name) {
          return {
            key: name,
            fn: function() {
              return undefined;
            },
            proxy: true,
          };
        }),
      ],
      null,
      true,
    ),
  });
}

已经找到问题原因,在 vue-template-compiler build.js L2470-L2471,动态具名插槽名称 相同的情况下后者会替换前者。

此处我认为应该针对 动态具名插槽名称 进行判断,如果相同,则向名称添加额外唯一标识,防止被后者替换前者的情况出现。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions