我创建了一个非Nuxt Vue目录,以使用v-touch进行播放。我在该目录中使用了v-touch组件。
我现在正在尝试将工作代码移植到使用Nuxt的Vue设置中,但是我经常遇到以下错误:Unknown custom element: <v-touch> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
我在global.js
中有一个/plugins/
文件,它可以:
import Vue from 'vue'
if (process.browser) {
window.onNuxtReady(() => {
const VueTouch = require('vue-touch')
Vue.use(VueTouch)
})
}
在我的nuxt.config.js
文件中,我有:vendor: ['vue-touch']
和plugins: [{ src: '~plugins/global', ssr: false }]
然后在我的`.Vue中。文件,这是我要呈现的HTML模板:
<template>
<no-ssr>
<div class="main">
<div id="slider" class="slider" >
<v-touch @pan="mouseMoving" @panend="stopDrag" @swipe="startDrag">
<div class="slider-cards" :style="`transform: translate3d(${cardsX}px,0,0)`">
<div v-for="num in 3" class="slider-card">
<Card />
</div>
</div>
</v-touch>
</div>
</div>
</no-ssr>
</template>
我尝试了各种组合,包括以不同形式(包括导入,需求等)包含依赖项,但是我不知道如何使此依赖项按应有的方式运行。我会感谢您的帮助!