如何封装/包装VueJS组件?(How to encapsulate / wrap a VueJS component?)
大家好,请原谅我的英语:-)
我有一个可以带动态插槽的Vue组件(插槽的名称将取决于道具)。
我在几个地方使用它,并且一些插槽总是存在。
为了避免冗余,我正在寻找一种方法来创建一个“包装”最终组件的组件,以允许我只定义添加插槽。
如果有一种“明显”的方式来实现它,我可能会错过它:-)
代码示例
没有“包装组件”
<b-table show-empty small hover [...some others and always present props...] :items="aDataVarThatWillChangeBasedOnTheContext" [...some others and uniq props...] > <template slot="same-1"> A slot that will always be present with the same content (for example, a checkbox in the first column) </template> <template slot="same-2"> A slot that will always be present with the same content (for example, some action buttons in the last column) </template> [...some others and always present slots...] <template slot="not-the-same"> A slot that is only used in this context (for example, a duration based on a row timestamp and a timestamp picked by the user) </template> [...some others and uniq slots...] </b-table>
使用“换行组件”
<my-b-table :items="aDataVarThatWillChangeBasedOnTheContext" > <template slot="not-the-same"> A slot that is only used in this context (for example, a duration based on a row timestamp and a timestamp picked by the user) </template> </my-b-table>
注意:动态插槽名称不可预测。 如果我突然需要一个“foo”列,我应该能够通过一个“foo”插槽(和一个“HEAD_foo”插槽,就我而言)
一些研究
我在这里读到:
它们(功能组件)作为包装组件也非常有用。 例如,当你需要:
- 以编程方式选择要委派的其他组件之一
- 在将它们传递给儿童组件之前,操作儿童,道具或数据
而且“在将孩子,道具或数据传递给儿童组件之前操作儿童,道具或数据”似乎正是我所需要的。
我着眼于渲染功能,但很多东西似乎没有实现,比如v模型,我很难弄清楚如何通过动态插槽。
预先感谢您的回答(s)!
up:在07.03.2018我还没有任何关于如何解决这个案件的想法
Hi everybody, please pardon my english :-)
I have a Vue component that can take dynamic slots (the names of the slots will depend on a props).
I use it on several places and some of the slots are always present.
To avoid redundancy, I'm looking for a way to create a component that "wrap" the final component to allow me to define only the additionals slots.
If there is an "obvious" way to achieve it, I may have missed it :-)
Code example
Without a "wrap component"
<b-table show-empty small hover [...some others and always present props...] :items="aDataVarThatWillChangeBasedOnTheContext" [...some others and uniq props...] > <template slot="same-1"> A slot that will always be present with the same content (for example, a checkbox in the first column) </template> <template slot="same-2"> A slot that will always be present with the same content (for example, some action buttons in the last column) </template> [...some others and always present slots...] <template slot="not-the-same"> A slot that is only used in this context (for example, a duration based on a row timestamp and a timestamp picked by the user) </template> [...some others and uniq slots...] </b-table>
With a "wrap component"
<my-b-table :items="aDataVarThatWillChangeBasedOnTheContext" > <template slot="not-the-same"> A slot that is only used in this context (for example, a duration based on a row timestamp and a timestamp picked by the user) </template> </my-b-table>
Note: The dynamic slot name is not predictible. If I suddenly need a "foo" column, I should be able to pass a "foo" slot (and a "HEAD_foo" slot, in my case)
Some researches
I read here that:
They’re (the functionnal components) also very useful as wrapper components. For example, when you need to:
- Programmatically choose one of several other components to delegate to
- Manipulate children, props, or data before passing them on to a child component
And "Manipulate children, props, or data before passing them on to a child component" seems to be exactly what I need.
I looked on render function but a lot of things seems to be not implemented, like the v-model, and I have difficulties to figure out how to pass dynamic slots...
Thank you in advance for your(s) answer(s) !
up: At the 07.03.2018 I still dont have any idea about how to solve this case
原文:https://stackoverflow.com/questions/48807290
最满意答案
您需要替换自定义用户模型 。
You will need to substitute custom user model.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
指定登录表(Specifying a login table)[2022-01-15]
您需要替换自定义用户模型 。 You will need to substitute custom user model. -
登录统计SQL表(Login Statistics SQL Table)[2023-01-13]
我会将所有内容保存在一起,并有一个列来跟踪登录是否成功。 请确保您不要将密码保存为纯文本。 I would save all in one, and have a column that keeps track of if the login was successful or not. Just make sure you dont save the passwords as plain text. -
使用单表继承登录(Login with Single Table Inheritance)[2022-01-16]
如果你不想使用get_class,你会做这样的事情 class Client extends Account { protected $discr = 'client'; ... } class Administrator extends Account { protected $discr = 'administrator'; ... } 对象中的字段(不在数据库中) 并在Acount类中创建getType()方法 if you do not want to use ... -
MySQL cli将位置参数视为数据库名称,使用--execute选项传递要运行的语句: mysql --login-path=remote --database=marketing --execute 'truncate table my_test_table' MySQL cli treats positional argument as database name, pass statement you want to run with --execute option: mysql --login ...
-
登录表结构(Login Table structure)[2022-01-29]
一个好的做法是将ROLE表映射到USER表,这样用户可以拥有多个角色。 对于我在评论中提到的第二个问题,我会将所有数据放在user表中,但如果需要在两个表中分隔数据,则可以这样做。 只需将user_details表映射到user表即可。 ( user_details user_id ) 表用户 ID | USERNAME | PASSWORD ------------------------- 1 | bill | 09hk4352 /* password should be encoded ... -
在将输入密码保存到数据库之前对其进行加密 $user->password = bcrypt('MyNewPassword'); $user->save() (如果你没有修改Laravel使用另一个地穴算法,它会工作) bcrypt the input password before saving it to the database $user->password = bcrypt('MyNewPassword'); $user->save() (It will work if you didn't m ...
-
看起来你正在混合一些东西。为了创建一个代理表,你不需要sp_remotelogin创建的“远程登录”。 但是,您需要外部登录,它应该在远程服务器中实际登录。 有关更多建议,您应该发布所采取的确切步骤以及错误输出。 Dears, kindly note that the problem is solved, the case was the password, the passwords for local login and remote login are different, so I add the ...
-
选项3是你最好的,恕我直言。 1)安全 必须窃取多个表才能丢失所有客户端安全数据。 考虑限制您的风险和责任。 1a)还...... 你有什么需要知道哪个facebook登录与哪个openID登录相关联? 或许,但无论如何,对于数据窃贼来说,如果你把它们全部放在一起对它们来说肯定会很方便(选项1) 2)表格功能 - 例如触发器,计算字段,或者您可能(?)以独特的方式为每个提供商使用的内容。 3)如果你真的必须将一切都放在一个表中以用于奇怪/临时目的,你仍然可以用视图完成这个。 4)设计优化。 机会是,数据非常 ...