V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
yantianqi
V2EX  ›  程序员

vue 中如何获取 slot 中的内容

  •  
  •   yantianqi · Jan 17, 2018 · 6933 views
    This topic created in 3024 days ago, the information mentioned may be changed or developed.
    <template>
      <div>
        <slot></slot>
      </div>
    </template>
    <script>
    export default {
    	//怎么获取 slot 中的内容呢?
    }
    </script>
    
    4 replies    2018-01-17 16:35:32 +08:00
    changlers
        1
    changlers  
       Jan 17, 2018
    changlers
        2
    changlers  
       Jan 17, 2018
    父向子传值用 props,子向父传值用 emit 事件,分别为
    ```javascript
    <parent>
    <son :param="param"></son>
    </parent>

    <parent>
    <son @sonEvent="handle"></son>
    </parent>
    ```
    vinsony
        3
    vinsony  
       Jan 17, 2018
    this.$slots.default
    pelloz
        4
    pelloz  
       Jan 17, 2018
    你再想想,我猜你不应该直接从父节点获取子节点的内容。
    你可以看看 https://cn.vuejs.org/v2/guide/components.html#编写可复用组件
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   939 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:25 · PVG 04:25 · LAX 13:25 · JFK 16:25
    ♥ Do have faith in what you're doing.