jsPlumb 与 Nuxtjs 集成抛出错误文档未定义

jsPlumb integration with Nuxtjs throwing the error document is not defined(jsPlumb 与 Nuxtjs 集成抛出错误文档未定义)

本文介绍了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:

  1. npm i jsplumb --save
  2. 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

这篇关于jsPlumb 与 Nuxtjs 集成抛出错误文档未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:jsPlumb 与 Nuxtjs 集成抛出错误文档未定义

基础教程推荐