简体   繁体   English

nuxt 生成的 static 站点上未加载 Vue 插件

[英]Vue plugin not loaded on static site generated by nuxt

In my nuxt.js project I am using a component from a Vue library called vue-tailwind .在我的 nuxt.js 项目中,我使用了一个名为vue- tailwind 的 Vue 库中的组件。

I import the library as a plugin in this way (as advised by the author):我以这种方式将库作为插件导入(按照作者的建议):

/plugins/vue-tailwind.js /plugins/vue-tailwind.js

import Vue from 'vue'
import VueTailwind from 'vue-tailwind'
Vue.use(VueTailwind)

/nuxt.config.js /nuxt.config.js

  plugins: ['~plugins/vue-tailwind']

and the component works perfectly in development.并且该组件在开发中完美运行。

My problem is that the component is not rendered when I serve the app generated with我的问题是,当我为使用生成的应用程序提供服务时,该组件未呈现

nuxt generate

I already tried to load the plugin this way:我已经尝试过以这种方式加载插件:

    { src: '~plugins/vue-tailwind', mode:  'client' }

and also tried to put the component between client-only tag并且还尝试将组件放在仅客户端标签之间

<client-only>
            <t-datepicker
              v-model="date"
              :max-date="today"
              placeholder="Select a date"
              date-format="Y-m-d"
              user-format="d-M-Y"
            />
</client-only>

After several attempt, I understood that the component has to be registered in the plugin.经过几次尝试,我了解到该组件必须在插件中注册。 Vue.use does not work in generated code. Vue.use在生成的代码中不起作用。

My final working code is the following:我的最终工作代码如下:

/plugins/vue-tailwind.js /plugins/vue-tailwind.js

import Vue from 'vue'
import { TDatepicker } from 'vue-tailwind/dist/components';
Vue.component('t-datepicker', TDatepicker)

I've got the same problem and that could be fixed by setting ssr: false in the nuxt.config.js我遇到了同样的问题,可以通过在nuxt.config.js中设置ssr: false来解决

export default {
    ssr: false,
    target: 'static'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM