Easy way to set a slot with a string of a variable?

主宰稳场 提交于 2019-12-02 18:19:07

问题


There are many slot examples but no clair and simple as I need... I need something like

 var x="Hello";
 $slot = x;

that is what I need...

In a concrete example: https://jsfiddle.net/2qdh3x3v/
I need a easy way to set slot header to "HELLO" when click "ShowModal1", and to "BYE!" when click "ShowModal2".


回答1:


You can create a variable and change it by clicking on the desired button:

<button id="show-modal" @click="(header = 'HELLO') && (showModal = true)">
  Show Modal1
</button>
<button id="show-modal" @click="(header = 'BYE!') && (showModal = true)">
  Show Modal2
</button>
...
<h3 slot="header">{{header}}</h3>

https://jsfiddle.net/6k9drL1t/1/



来源:https://stackoverflow.com/questions/49202998/easy-way-to-set-a-slot-with-a-string-of-a-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!