繁星點點滴滴
2019-02-20 10:19:55
如何解決vue 父組件 模板 傳遞到 孫子組件中去孫子組件子組件調用期望結果我嘗試用slot解決 但是不奏效 原因是 所處的作用域 是 中無法被渲染到有什么方法能解決這個問題呢 或者 這種方式不能解決(唯一想到的是通過js字符串傳入 在渲染 但是寫起來 不太友好(需要些一堆字符串))貌似vue不能做到react的將jsx模板一樣 傳到 一級級的子組件中去 在渲染
1 回答

呼如林
TA貢獻1798條經驗 獲得超3個贊
每一個被繼承的組件都需要有slot;
father.vue
<template>
<div class="father">
<h1>father</h1>
<slot></slot>
</div>
</template>
child.vue
<template>
<div class="child">
<h2>child</h2>
<slot></slot>
</div>
</template>
subchild.vue
<template>
<div class="subchild">
<Father>
<Child>
<h3>subchild</h3>
</Child>
</Father>
</div>
</template>
<script>
import Father from './father'
import Child from './child'
export default {
components: {
Father,
Child,
}
}
</script>
效果:
添加回答
舉報
0/150
提交
取消