在vue项目中jsPlumb制作流程图,拖拽复制使用 jquery 和 jquery UI

这是早期用jsPlumb做流程图走的一个坑,使用jquery来制作流程图,最近换成了用go.js来制作流程图后,可以使用go.js中自带的方法来制作拖拽效果,就不再使用jquery了。

用jsPlumb做流程图的项目,有一项功能是要从左侧的菜单栏拖动项目到右侧的面板上。参考了一些博客和demo,决定使用 jquery UI 中的 DraggableDroppable 功能。

这里面遇到的问题就是,如何在 vue 中引入 jquery UI

  • 本地安装 jquery 和 jquery UI
npm install jquery --save
npm install jquery-ui --save

  • 配置 webpack.base.conf.js 文件
// 在开头引入webpack,后面的plugins那里需要
const webpack = require('webpack')
// ...
resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'jquery': 'jquery',
      'jquery-ui': 'jquery-ui'
    }
  },
  // 增加一个plugins
  plugins: [
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      jquery: "jquery",
      "window.jQuery": "jquery"
    })
  ],

  • 在项目文件中,即需要引入jqueryUI的的地方import文件
<script type="text/ecmascript-6">
  import { jsPlumb } from 'jsplumb'
  import $ from 'jquery'
  // 需要注意的是,jquery-ui引入的时候,
  // 直接写 import juqery-ui 没有效果,只能直接写到具体的方法
  // 好处是需要引用的也只有两个  draggable  droppable
  import 'jquery-ui/ui/widgets/draggable'
  import 'jquery-ui/ui/widgets/droppable'
  import 'jquery-ui/ui/widgets/resizable'

  export default {
    name: 'flowedit',
    mounted: function() {
      this.flowEdit()
    },
    methods: {
      flowEdit: function() {
        // 此处是等到jquery加载上再去运行jquery-ui
        $(document).ready(function() {
          $('.item').resizable()
        })
        jsPlumb.ready(function() {
          const common = {
            isSource: true,
            isTarget: true,
            endpoint: 'Rectangle',
          }
          jsPlumb.connect({
            source: 'item_left',
            target: 'item_right'
          }, common)
          jsPlumb.draggable('item_left')
          jsPlumb.draggable('item_right')
        })
      }
    }
  }
</script>

  • 这里面有个坑是,因为jqueryUI中的resizable()方法需要引入jqueryUI的css文件,所以需要在根目录的index.html中引入该文件
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <title></title>
    // 此处引入了jquery UI的css文件
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
  </head>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值