anonymous2351d00
V2EX  ›  Vue.js

Q: Vue3 有没有模板声明成变量的方式? Vue3 如何把组件当做参数传入?

  •  
  •   anonymous2351d00 · Dec 19, 2022 · 2164 views
    This topic created in 1265 days ago, the information mentioned may be changed or developed.

    intro.什么是模板变量?

      // 这里在 html 中把 img 元素声明成一个模板变量 HeaderImg
      <ng-template #headerImg>
          <img src="xxxx"></img>
      </ng-template>
      
      
      // 使用 把 headerImg 这个 html 当做参数传入了<layout-default>这个组件里
      <layout-default  [userImg]="headerImg"></layout-default>
      
      
      // 在<layout-default>组件中使用了上层组件传入的 headerImg(本层是 userImg)的 html 代码片段
      <ng-container *ngTemplateOutlet="userImg"></ng-container>
    

    Question-1

    请问 Vue3 有没有这种书写方式?

    Question-2

    请问 Vue3 可不可以把 组件 当做参数传入下层组件中?

    4 replies    2022-12-20 14:25:26 +08:00
    anonymous2351d00
        2
    anonymous2351d00  
    OP
       Dec 19, 2022
    @Huelse 感谢大佬
    agileago
        3
    agileago  
       Dec 20, 2022   ❤️ 1
    蹩脚的模板语法模拟 renderProps
    anonymous2351d00
        4
    anonymous2351d00  
    OP
       Dec 20, 2022
    @agileago react 怎么都行,随便传个 callback 都可以实现了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2782 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 15:11 · PVG 23:11 · LAX 08:11 · JFK 11:11
    ♥ Do have faith in what you're doing.