各个命名槽位的内容没有显示出来。

huangapple go评论48阅读模式
英文:

respective contents of each named slot do not show up

问题

关于此链接,我试图实现与该链接中提供的示例相同的内容。对于下面发布的代码,尽管我在BaseLayer_0.vue中为每个插槽分配了名称,但使用v-slot#绑定到每个命名插槽的内容却不起作用,而是得到如下图部分所示的输出。

请告诉我我做错了什么,以致我无法看到各个插槽的内容。

App:

<template>
  <img alt="Vue logo" src="./assets/logo.png">
  <HelloWorld msg="Welcome to Your Vue.js App"/>

  <BaseLayer_0>
    <template #header>
      <h1>header</h1>
    </template>

    <template #default>
      <p>default</p>
    </template>

    <template #footer>
      <p>footer</p>
    </template>
  </BaseLayer_0>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
import BaseLayer_0 from './components/BaseLayer_0.vue'

export default {
  name: 'App',
  components: {
    HelloWorld,
    BaseLayer_0
  }
}
</script>

BaseLayer_0:

<template>
  <div class="container">
    <header name="header">
      <slot></slot>
    </header>

    <main>
      <slot></slot>
    </main>

    <footer name="footer">
      <slot></slot>
    </footer>
  </div>
</template>

<script>

export default {
  name: 'BaseLayer_0',
  
}
</script>

image:

各个命名槽位的内容没有显示出来。

英文:

Referring to this link , i am trying to implement the same example provided in the url.
for the below posted code, despite i assigned names to each slot as shown in BaseLayer_0.vue,the content bound to each named slot using v-slot or # does not work, and instead i receive the output shown in the image section below.

please let me know what have i done wrong so that i am not able to see contents of each slot respectively

App:

&lt;template&gt;
  &lt;img alt=&quot;Vue logo&quot; src=&quot;./assets/logo.png&quot;&gt;
  &lt;HelloWorld msg=&quot;Welcome to Your Vue.js App&quot;/&gt;

  &lt;BaseLayer_0&gt;
	&lt;template #header&gt;
	  &lt;h1&gt;header&lt;/h1&gt;
	&lt;/template&gt;

	&lt;template #default&gt;
	  &lt;p&gt;default&lt;/p&gt;
	&lt;/template&gt;

	&lt;template #footer&gt;
	  &lt;p&gt;footer&lt;/p&gt;
	&lt;/template&gt;
  &lt;/BaseLayer_0&gt;

&lt;/template&gt;

&lt;script&gt;
import HelloWorld from &#39;./components/HelloWorld.vue&#39;
import BaseLayer_0 from &#39;./components/BaseLayer_0.vue&#39;

export default {
  name: &#39;App&#39;,
  components: {
	HelloWorld,
	BaseLayer_0
  }
}
&lt;/script&gt;

BaseLayer_0

&lt;template&gt;
  &lt;div class=&quot;container&quot;&gt;
	&lt;header name=&quot;header&quot;&gt;
		&lt;slot&gt;&lt;/slot&gt;
	&lt;/header&gt;

	&lt;main&gt;
		&lt;slot&gt;&lt;/slot&gt;
	&lt;/main&gt;

	&lt;footer name=&quot;footer&quot;&gt;
		&lt;slot&gt;&lt;/slot&gt;
	&lt;/footer&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;

export default {
  name: &#39;BaseLayer_0&#39;,
  
}
&lt;/script&gt;

image:

各个命名槽位的内容没有显示出来。

答案1

得分: 0

你应该将 name 属性添加到 &lt;slot&gt; 标签,而不是 &lt;header&gt;

例如:

#BaseLayer_0.vue

&lt;header&gt;
   &lt;slot name=&quot;header&quot;&gt;
&lt;/header&gt;
英文:

You should add the name attribute to the &lt;slot&gt; tag, not to &lt;header&gt;.

For example:

#BaseLayer_0.vue

&lt;header&gt;
   &lt;slot name=&quot;header&quot;&gt;
&lt;/header&gt;

huangapple
  • 本文由 发表于 2023年6月8日 13:15:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428792.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定