This time I will bring you How vue slot displays parent component delivery in child components. What are the precautions for vue slot to display parent component delivery in child components? The following This is a practical case, let’s take a look at it.
The parent component uses no specified slot attribute, the default is default
You can use the default value in the slot. If the parent component does not pass the corresponding slot, the default value will be displayed
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="vue.js" charset="utf-8"></script> </head> <body> <p id="app"> <modal> <!-- 调用父组件的方法 --> <h1 @click='click'>aaa</h1></modal> <modal> <h2>bbb</h2></modal> <modal> <!-- 使用slot设置模板中的名字,会插入到指定的slot中 --> <p slot='title'>hello</p> <p slot='content'> world </p> </modal> <modal></modal> </p> <template id="modal"> <!-- 使用slot在子组件中显示父组件传过来的模板 --> <p> modal <slot name='default'>如果没有会使用这个默认值</slot> <h1> title: <slot name='title'> </slot> </h1> content: <slot name='content'></slot> </p> </template> <script type="text/javascript"> let modal = { template: '#modal' } new Vue({ el: '#app', components: { // es 简写 ,只写一个的意思为 // modal:modal modal }, methods: { click() { console.log('aaa') } } }) </script> </body> </html>
I believe I read it You have mastered the method in the case of this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
ul of Vue.js How does the -li tag imitate the select tag
ajax dynamic assignment data graph
The above is the detailed content of How to display parent component delivery in vue slot in child component. For more information, please follow other related articles on the PHP Chinese website!