我想在Vue组件中使用Choices.js。该组件编译成功,但随后就会触发一个错误:“文档未定义”在Nuxt.js
[vue-router] Failed to resolve async component default: ReferenceError: document is not defined
在浏览器中我看到:
ReferenceError document is not defined
我觉得这事做与SSR在Nuxt.js?我只需要Choices.js在客户端上运行,因为它只是客户端的一个方面。
nuxt.config.js
build: {
vendor: ['choices.js']
}
AppCountrySelect.vue
<script>
import Choices from 'choices.js'
export default {
name: 'CountrySelect',
created() {
console.log(this.$refs, Choices)
const choices = new Choices(this.$refs.select)
console.log(choices)
}
}
</script>
在经典Vue公司,这会工作得很好,所以我非常仍然得到认真处理我如何让Nuxt.js以这种方式工作。
任何想法,我要去哪里错了?
谢谢。
感谢这个!任何想法我怎么能然后用SSR输出元素本身?如同一样,一些JS需要在客户端执行一个选择列表,但我仍然想要在服务器上呈现实际的选择列表。 –