jsPlumb 与 Nuxtjs 集成抛出错误文档未定义
I know there are a few questions similar to this but they did not work for me so I am posting this.
I am trying to add jsPlumb
into my Nuxtjs/Vuejs
application. I did the following steps:
npm i jsplumb --save
- Create a
Vuejs
page and add the simple code:
<template>
<client-only>
<div id="canvas" />
</client-only>
</template>
<script>
import { jsPlumb } from 'jsplumb'
export default {
mounted () {
if (process.client) {
console.log('MOUNTED - 2')
jsPlumb.ready(function () {
console.log('MOUNTED - 3')
})
}
}
}
</script>
I get the error:
ReferenceError
document is not defined
I tried many things which were mentioned but nothing seems to work.
解决方案Instead of using process.client
I used the process.browser
and it worked fine for me. Please refer the link: https://stackoverflow.com/a/69822954/7584240
相关文章