Home > Web Front-end > Vue.js > How to use slot-scope in vue

How to use slot-scope in vue

下次还敢
Release: 2024-05-02 22:09:33
Original
1150 people have browsed it

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.

How to use slot-scope in vue

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>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template