Home > Article > Web Front-end > How to use slot-scope in vue
The slot-scope attribute in Vue.js allows passing data within the slot through the specified scope variable. Specific usage methods include: specifying the slot-scope attribute and the variable name for receiving data on the slot element; using v-slot in the parent component to pass data.
Usage of slot-scope in Vue.js
slot-scope attribute allows Pass data when using the slot, thereby using the data within the slot. It creates a scope in the slot template to access data outside the slot.
Usage
<slot>
Use the slot-scope
attribute on the element to specify a variable name to receive Data outside the slot. For example:
<code class="html"><slot name="header" slot-scope="headerData"> <h1>{{ headerData.title }}</h1> </slot></code>
Then, in the parent component, use the v-slot
slot property to pass data to the slot. For example:
<code class="html"><template> <div> <slot name="header" v-slot="headerData"> headerData: {{ headerData }} </slot> </div> </template> <script> export default { data() { return { headerData: {</code>
The above is the detailed content of How to use slot-scope in vue. For more information, please follow other related articles on the PHP Chinese website!