[英]How to import the folder as Vue component
I want to display different Vue component for the mobile device.我想为移动设备显示不同的 Vue 组件。 And I found this solution ( https://stackoverflow.com/a/48515205/11079653 ) via mixin.
我通过 mixin 找到了这个解决方案( https://stackoverflow.com/a/48515205/11079653 )。
And, for example, I have the component - Card.vue.而且,例如,我有组件 - Card.vue。 But for the mobile device, I have created CardMovile.Vue.
但是对于移动设备,我创建了 CardMovile.Vue。
Now I want to put these components in the folder Card which will contain index.js现在我想将这些组件放在包含 index.js 的文件夹 Card 中
-Card
--Card.vue
--CardMobile.vue
--index.js
After that, I just want import Card in my App.vue and index.js should decide what component needed (Card.vue or Card.mobile.vue)之后,我只想在我的 App.vue 中导入 Card,index.js 应该决定需要什么组件(Card.vue 或 Card.mobile.vue)
<template>
<Card></Card>
</template>
<script>
import Card from './Card'
</script>
is it possible?是否可以?
You could try to write the following in the Card/index.js
file:您可以尝试在
Card/index.js
文件中写入以下内容:
import isMobile from 'is-mobile'
import Card from './Card.vue'
import CardMobile from './CardMobile.vue'
export default isMobile() ? CardMobile : Card
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.