4
在nuxt中,引用Toast,服务端渲染报错
vant插件代码 plugins/vant
import Vue from 'vue';
import { Checkbox, Button, Dialog, Popup, Toast } from 'vant';
Vue.use(Checkbox);
Vue.use(Button);
Vue.use(Dialog);
Vue.use(Popup);
Vue.use(Toast);
页面组件代码 page:
import { Toast } from 'vant';
...
Toast.loading({
message: '加载中...'
});
nuxt配置代码 nuxt.config.js:
build: {
vendor: ['vant'],
babel: {
plugins: ['transform-vue-jsx', ['component', {
libraryName: 'vant',
styleLibraryName: 'vant-css',
style: true
}]]
},
...
plugins: [ '~/plugins/vant' ]