Slideshow is properly showed only first time, then it dissapears - vue.js

I have a problem properly displaying slideshow (which is written in Jquery) when i revisit web page (via router-link)...
So if i press f5 and web page reloads, everything is working properly, but once i click on one link and i'm redirected, half of web page is blank... I belive that problem is because a lot of parts of this application is in jquery code. I bought a template and include it in to my Vuejs2 project
Example of home component
<template>
<div id="wrapper">
<HeaderComponent></HeaderComponent>
<div id="main-content">
<SlideShow></SlideShow>
</div>
<FooterComponent></FooterComponent>
</div>
</template>
<script>
import HeaderComponent from './HeaderComponent.vue'
import SlideShow from './subComponents/SlideShow.vue'
import FooterComponent from './FooterComponent.vue'
export default {
name: 'Home',
components: {
'HeaderComponent': HeaderComponent,
'SlideShow': SlideShow,
'FooterComponent': FooterComponent
}
}
</script>
Slideshow component
<template>
<div class="">
<div class="rev_slider_wrapper">
<div id="rev_slider" data-slider-layout="fullscreen" data-slider-thumbnail="true" class="rev_slider">
<ul>
<li><img src="static/img/various/bg-image.png"/></li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'SlideShow'
}
</script>
This is the slider.js included in index.html via tag
$(document).ready(function () {
// MAIN VARIABLES INITIALIZATION
var revapi;
$(window).resize(function () {
'use strict';
if ($('#rev_slider').data('slider-layout') == 'fullscreen' && $('body').hasClass('left-nav')) {
var windowHeight = $(window).height();
$('.rev_slider_wrapper, #rev_slider').height(windowHeight);
}
});
(function () {
'use strict';
slickCarousel();
setTimeout(function () {
revSlider();
owlCarousel();
}, 100);
bxSlider();
flexslider();
}());
// REVOLUTION SLIDER
function revSlider() {
if ($.fn.revolution && $('#rev_slider').length) {
var revSliderLayout = $('#rev_slider').data('slider-layout') ? $('#rev_slider').data('slider-layout') : 'auto';
var revSliderHeight = $('#rev_slider').data('gridheight') ? $('#rev_slider').data('gridheight') : [800, 800, 480, 360];
var windowHeight = $(window).height();
if ($('body').hasClass('left-nav')) {
revSliderLayout = 'auto';
if ($('#rev_slider').data('slider-layout') == 'fullscreen') {
revSliderHeight = windowHeight;
}
}
revapi = $('#rev_slider').show().revolution({
sliderType: $('#rev_slider').data('slider-type') ? $('#rev_slider').data('slider-type') : 'standard',// standard, hero, carousel
jsFileLocation: 'static/js/plugins/revolution-slider/revolution/js/',
sliderLayout: revSliderLayout, // auto, fullscreen, fullwidth
dottedOverlay: 'none',
delay: 9000,
lazyLoad: 'on',
navigation: {
keyboardNavigation: 'on',
keyboard_direction: 'horizontal',
mouseScrollNavigation: $('#rev_slider').data('nav-mouse') ? $('#rev_slider').data('nav-mouse') : 'off',
onHoverStop: 'off',
touch: {
touchenabled: 'on',
swipe_threshold: 75,
swipe_min_touches: 1,
swipe_direction: 'horizontal',
drag_block_vertical: false
},
arrows: {
style: 'zeus',
enable: $('#rev_slider').attr('data-nav-arrows') ? false : true,
hide_onmobile: false,
hide_onleave: false,
tmp: $('#rev_slider').data('slider-thumbnail') ? '<div class="tp-title-wrap"><div class="tp-arr-imgholder"></div></div>' : '<div class="tp-title-wrap"></div>',
left: {
h_align: 'left',
v_align: 'center',
h_offset: 10,
v_offset: 0
},
right: {
h_align: 'right',
v_align: 'center',
h_offset: 10,
v_offset: 0
}
},
bullets: {
enable: $('#rev_slider').attr('data-nav-bullets') ? true : false,
hide_onmobile: false,
style: 'uranus',
hide_onleave: false,
direction: 'vertical',
h_align: $('#rev_slider').data('bullets-align') ? $('#rev_slider').data('bullets-align') : 'left',
v_align: 'center',
h_offset: 30,
v_offset: 0,
space: 10,
tmp: '<span class="tp-bullet-inner"></span>'
}
},
carousel: {
maxRotation: 5,
vary_rotation: "off",
minScale: 15,
vary_scale: "off",
horizontal_align: "center",
vertical_align: "center",
fadeout: "on",
vary_fade: "on",
maxVisibleItems: 3,
infinity: "off",
space: -80,
stretch: "off"
},
responsiveLevels: $(this).data('responsive') ? $(this).data('responsive') : [1240, 1024, 778, 480],
gridwidth: $(this).data('gridwidth') ? $(this).data('gridwidth') : [1230, 1024, 767, 480],
gridheight: revSliderHeight,
lazyType: 'none',
parallax: {
type: 'mouse',
origo: 'slidertop',
speed: 2000,
levels: [2, 3, 4, 5, 6, 7, 12, 16, 10, 50],
disable_onmobile: 'on'
},
shadow: 0,
spinner: 'off',
stopLoop: 'on',
stopAfterLoops: 0,
// stopAtSlide: $('#rev_slider').data('autoplay') ? 0 : 1,
shuffle: 'off',
autoHeight: 'off',
disableProgressBar: 'on',
hideThumbsOnMobile: 'off',
hideSliderAtLimit: 0,
hideCaptionAtLimit: 0,
hideAllCaptionAtLilmit: 0,
startWithSlide: 0,
fallbacks: {
simplifyAll: 'off',
nextSlideOnWindowFocus: 'off',
disableFocusListener: 'off'
}
});
revapi.bind("revolution.slide.onbeforeswap", function (e) {
if ($('#rev_slider').data('slider-layout') == 'fullscreen' && $('body').hasClass('left-nav')) {
var windowHeight = $(window).height();
$('.rev_slider_wrapper, #rev_slider').height(windowHeight);
}
});
revapi.bind('revolution.slide.onchange', function (event, data) {
var logoImg = $('#logo a img');
var logoLight = $('#logo a').data('logo-light');
var logoDark = $('#logo a').data('logo-dark');
var currentSlide = data.slideIndex;
if (revapi.find('li').eq(data.slideIndex - 1).attr('data-color') === 'dark') {
$('body').addClass('transparent-dark');
logoImg.attr('src', logoDark);
}
if (revapi.find('li').eq(data.slideIndex - 1).attr('data-color') === 'light') {
$('body').removeClass('transparent-dark');
logoImg.attr('src', logoLight);
}
});
$('body').on('click', '[data-go-to-slide]', function () {
var goToSlide = $(this).data('go-to-slide');
revapi.revshowslide(goToSlide);
return false;
});
setTimeout(function () {
revapi.revredraw();
}, 400);
}
}
});
So how to properly reinitialise, reload, do something with this slideshow, so it will be re rendered when i visit page via .
If you need any additional informations please let me know and i will provide. Thank you!

i managed to solve it by calling Jquery function in mounted function
example:
export default {
name: 'SlideShow',
methods: {
},
mounted: function () {
// initial start of slide show
revSlider();
}
}
And this is example how my external sliders.js script looks like
// MAIN VARIABLES INITIALIZATION
var revapi;
$(window).resize(function () {
'use strict';
if ($('#rev_slider').data('slider-layout') == 'fullscreen' && $('body').hasClass('left-nav')) {
var windowHeight = $(window).height();
$('.rev_slider_wrapper, #rev_slider').height(windowHeight);
}
});
(function () {
'use strict';
setTimeout(function () {
revSlider();
}, 1000);
}());
stopAtSlide:1
// REVOLUTION SLIDER
function revSlider() {
if ($.fn.revolution && $('#rev_slider').length) {
var revSliderLayout = $('#rev_slider').data('slider-layout') ? $('#rev_slider').data('slider-layout') : 'auto';
......

Related

How to remove line over the stroke line in area chart - Apexchart?

How to remove line over the stroke line in area chart - Apexchart. the image
Please help me to fix this!
Here is my code so far
<template>
<div id="chart">
<apexchart
ref="pricesRef"
type="area"
height="150"
:options="options"
:series="series"
></apexchart>
<!-- <button #click="updateSeries">click</button> -->
</div>
</template>
<script>
import { axios } from 'boot/axios';
// import { dates, prices } from 'src/services/area-chart';
import { date } from 'quasar';
function formatNumber2(number, tofix) {
const val = (number / 1).toFixed(tofix).replace(',', ' ');
return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
let sharePrice = [];
const dataSharePrice = [];
export default {
name: 'AreaChart',
data() {
return {
timeInterval: 0,
dataSharePrice: [],
series: [
{
name: 'Share Price',
data: [
// { x: dates[0], y: prices[1] },
// { x: 1602392287529, y: 0.05 },
],
date: [],
},
],
options: {
chart: {
type: 'area',
zoom: {
enabled: false,
},
toolbar: {
show: false,
},
sparkline: {
enabled: true,
},
},
tooltip: {
custom({ series, w, dataPointIndex }) {
const unixTime = w.config.series[0].data[dataPointIndex].x;
const timeStamp = new Date(unixTime * 1000);
const hour = date.formatDate(timeStamp, 'DD MMMM');
return (
`
<div class="arrow_box_tooltip q-pa-md">
<span class="text-h6">
Date: ${hour}</span>
<br />
<span class="text-h6">
Share Price: $${formatNumber2(
series[0][dataPointIndex],
0,
)} USD</span>
</div>
`
);
},
},
noData: {
text: 'Loading...',
},
dataLabels: {
enabled: false,
},
stroke: {
curve: 'smooth',
lineCap: 'butt',
colors: undefined,
width: 2,
},
title: {
text: '',
align: 'left',
},
grid: {
show: false,
},
xaxis: {
type: 'datetime',
},
yaxis: {
opposite: true,
},
legend: {
horizontalAlign: 'left',
},
},
};
},
computed: {},
methods: {
getData() {
axios
.get(
'apiurl',
)
.then((response) => {
// console.log(response.data.prices);
sharePrice = response.data.prices;
})
.catch((err) => {
console.log(err);
});
},
updateSeriesData() {
for (const price of sharePrice) {
const unixTime = price[0];
if (Object.keys(price).length > 0) {
dataSharePrice.push({
x: unixTime,
y: price[1],
});
} else {
dataSharePrice.push({});
console.log('err');
}
// console.log(price[0], price[1]);
}
// console.log(dataSharePrice);
this.series[0].data = dataSharePrice;
this.$refs.pricesRef.updateSeries([
{
data: dataSharePrice,
},
]);
// console.log(this.$refs);
},
// timer() {},
},
mounted() {},
async created() {
await this.getData();
setTimeout(() => {
this.updateSeriesData();
// console.log('done');
}, 3000);
/* ; */
// this.timer();
},
beforeDestroy() {
// clearInterval(this.timer);
},
};
</script>
<style scoped>
/* #chart {
background-color: #18212f;
opacity: 1;
background-size: 7px 7px;
background-image: repeating-linear-gradient(
45deg,
#111726 0,
#111726 0.7000000000000001px,
#18212f 0,
#18212f 50%
);
} */
</style>
You can specify each stroke width separately by passing array
stroke: {
curve: 'smooth',
lineCap: 'butt',
colors: undefined,
width: [2,0],
},

VueJS + Chartjs - Chart only renders after code change

I'm using the following tutorial (pull download stats for NPM packages) to build a basis for my charted webapp :
https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44
https://github.com/apertureless/npm-stats
I have extracted the below code from the tutorial and modified it so it does the pure basics. Get data and present data. Specifically from these:
https://github.com/apertureless/npm-stats/blob/develop/src/pages/Start.vue
https://github.com/apertureless/npm-stats/blob/develop/src/components/LineChart.vue
Please note: The code executes the API call and retrieves data no problem. However it will only render that data in the chart if I make a code change. For example changing the color of a line to something else. It seems to only work on the next 'cycle' if that makes sense. Once the data has rendered, if I refresh that page it is once again blank. I suspect it has something to do with the pages timing. However not sure where to begin or what I'm looking for.
App.Vue
<template>
<v-app style="background-color: rgb(228, 228, 228);">
<section class="One">
<v-card class="One" color="rgb(255, 255, 255)" >
<LineChart :chart-data="downloads" :chart-labels="labels"/>
</v-card>
</section>
</v-app>
</template>
<script>
import axios from 'axios';
import LineChart from './components/test3.vue';
export default {
name: 'App',
components: {
LineChart,
},
data () {
return {
package: '',
packageName: '',
loaded: false,
loading: false,
downloads: [],
downloadsYear: [],
downloadsMonth: [],
downloadsWeek: [],
labels: [],
labelsYear: [],
labelsMonth: [],
labelsWeek: [],
showError: false,
showSettings: false,
errorMessage: 'Please enter a package name',
periodStart: '',
periodEnd: new Date(),
rawData: '',
totalDownloads: '',
dailyPng: null,
weeklyPng: null,
monthlyPng: null,
yearlyPng: null
}
},
mounted(){
this.loaded = false
axios.get(`https://api.npmjs.org/downloads/range/2017-01-01:2017-04-19/vue`)
.then(response => {
this.rawData = response.data.downloads
this.downloads = response.data.downloads.map(entry => entry.downloads)
this.labels = response.data.downloads.map(entry => entry.day)
this.packageName = response.data.package
this.totalDownloads = this.downloads.reduce((total, download) => total + download)
this.setURL()
this.groupDataByDate()
this.loaded = true
this.loading = false
})
.catch(err => {
this.errorMessage = err.response.data.error
this.loading = false
})
},
};
</script>
Chart Component:
<script>
import { Line } from 'vue-chartjs'
export default {
extends: Line,
props: {
chartData: {
type: Array,
required: false
},
chartLabels: {
type: Array,
required: true
}
},
data () {
return {
gradient: null,
options: {
showScale: true,
scales: {
yAxes: [{
ticks: {
beginAtZero: false,
},
gridLines: {
display: true,
color: '#EEF0F4',
borderDash: [5, 15]
}
}],
xAxes: [ {
gridLines: {
display: true,
color: '#EEF0F4',
borderDash: [5, 15]
}
}]
},
tooltips: {
backgroundColor: '#4F5565',
titleFontStyle: 'normal',
titleFontSize: 18,
bodyFontFamily: "'Proxima Nova', sans-serif",
cornerRadius: 3,
bodyFontColor: '#20C4C8',
bodyFontSize: 14,
xPadding: 14,
yPadding: 14,
displayColors: false,
mode: 'index',
intersect: false,
callbacks: {
title: tooltipItem => {
return `🗓 ${tooltipItem[0].xLabel}`
},
label: (tooltipItem, data) => {
let dataset = data.datasets[tooltipItem.datasetIndex]
let currentValue = dataset.data[tooltipItem.index]
return `📦 ${currentValue.toLocaleString()}`
}
}
},
legend: {
display: false
},
responsive: true,
maintainAspectRatio: false
}
}
},
mounted () {
this.gradient = this.$refs.canvas
.getContext('2d')
.createLinearGradient(0, 0, 0, 450)
this.gradient.addColorStop(0, 'rgba(52, 217, 221, 0.6)')
this.gradient.addColorStop(0.5, 'rgba(52, 217, 221, 0.25)')
this.gradient.addColorStop(1, 'rgba(52, 217, 221, 0)')
this.renderChart({
labels: this.chartLabels,
datasets: [
{
label: 'downloads',
borderColor: '#249EBF',
pointBackgroundColor: 'rgba(0,0,0,0)',
pointBorderColor: 'rgba(0,0,0,0)',
pointHoverBorderColor: '#249EBF',
pointHoverBackgroundColor: '#fff',
pointHoverRadius: 4,
pointHitRadius: 10,
pointHoverBorderWidth: 1,
borderWidth: 1,
backgroundColor: this.gradient,
data: this.chartData
}
]
}, this.options)
setTimeout(() => {
this.download()
}, 500)
},
methods: {
formatNumber (num) {
let numString = Math.round(num).toString()
let numberFormatMapping = [[6, 'm'], [3, 'k']]
for (let [numberOfDigits, replacement] of numberFormatMapping) {
if (numString.length > numberOfDigits) {
let decimal = ''
if (numString[numString.length - numberOfDigits] !== '0') {
decimal = '.' + numString[numString.length - numberOfDigits]
}
numString = numString.substr(0, numString.length - numberOfDigits) + decimal + replacement
break
}
}
return numString
}
}
}
</script>
You need to notify the child component to re-render itself.
add a watcher is one way, watch the data change and update it.
Another easier way is, add a key prop to it.
in your App.vue, do like this:
<LineChart :chart-data="downloads" :chart-labels="labels" :key="downloads.length"/>
here i'm using the downloads's length as key value. it's a simple and temp resolution to show you how to use key. In your app you should use some other value as key, incase different api call returns same length data.
you can also set the key to another value, and change this value every time you call the api.

Drilldown in Map with Vue.js

I'm trying to use the Drilldown in Map (vue-Highchart), but cannot get it working.
like this: https://www.highcharts.com/maps/demo/map-drilldown
Anyone have any examples of this in Vue.js? Please.
Tks.
Here is simple example of drilldown functionality(with vue-highcharts) which provides drilldown and drillup event from Vue-instance:
Vue.use(VueHighcharts, { Highcharts: Highcharts });
// helper script to load external script
let loadScript = function(url, onLoad){
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.onload = onLoad;
scriptTag.onreadystatechange = onLoad;
document.body.appendChild(scriptTag);
};
// simple chart options
var options = {
chart: {},
title: {
text: 'Highcharts-Vue Map Drilldown Example'
},
subtitle: {
text: '',
floating: true,
align: 'right',
y: 50,
style: {
fontSize: '16px'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
colorAxis: {
min: 0,
minColor: '#E6E7E8',
maxColor: '#005645'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
plotOptions: {
map: {
states: {
hover: {
color: '#EEDD66'
}
}
}
},
drilldown: {
activeDataLabelStyle: {
color: '#FFFFFF',
textDecoration: 'none',
textOutline: '1px #000000'
},
drillUpButton: {
relativeTo: 'plotBox',
position: {
x: 70,
y: 280
}
}
},
series: [{
data: Highcharts.geojson(Highcharts.maps['countries/us/us-all']).map((d, i) => {
d.drilldown = true;
// set value just for example
d.value = i;
return d;
}),
name: 'USA',
dataLabels: {
enabled: true,
format: '{point.properties.postal-code}'
}
}]
};
let vm = new Vue({
el: '#app',
data: {
isLoading: false,
options: options
},
created() {
// prepare events for chart from Vue instance
this.options.chart.events = {
drilldown: this.drilldown.bind(this),
drillup: this.drillup.bind(this)
}
},
methods: {
drilldown(e) {
let { chart } = this.$refs.highcharts;
if (!e.seriesOptions) {
mapKey = 'countries/us/' + e.point.properties['hc-key'] + '-all';
if (Highcharts.maps[mapKey]) {
this.prepareDrilldownData(mapKey, e.point);
return;
}
this.isLoading = true;
loadScript('https://code.highcharts.com/mapdata/' + mapKey + '.js', () => {
this.isLoading = false;
this.prepareDrilldownData(mapKey, e.point);
});
}
chart.setTitle(null, { text: e.point.name });
},
drillup(e) {
let { chart } = this.$refs.highcharts;
chart.setTitle(null, { text: '' });
},
prepareDrilldownData(mapKey, point) {
let { chart } = this.$refs.highcharts;
data = Highcharts.geojson(Highcharts.maps[mapKey]).map((d, i) => {
// set value just for example
d.value = i;
return d;
});
chart.addSeriesAsDrilldown(point, {
name: point.name,
data: data,
dataLabels: {
enabled: true,
format: '{point.name}'
}
});
}
}
});
<script src="https://cdn.jsdelivr.net/npm/vue#2.5.16/dist/vue.js"></script>
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/drilldown.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-highcharts/dist/vue-highcharts.min.js"></script>
<script src="https://code.highcharts.com/mapdata/countries/us/us-all.js"></script>
<div id="app">
<highmaps ref="highcharts" :options="options"></highmaps>
<div v-if="isLoading" style="text-align: center; margin-top: 15px; font-size: 20px;">Loading...</div>
</div>
There is also jsfiddle if you want.

Vue-Chartjs reactive chart options passing

So I follow the author's doc and make a reactive chart just as the doc sample.
A js file & a vue file :
// the chart.js file
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options'],
mounted () {
this.renderChart(this.chartData, this.options)
}
}
// the chart.vue file
<template>
<div style="background:#fff;">
<line-chart :chart-data="datacollection"></line-chart>
<button #click="fillData()">Randomize</button>
</div>
</template>
<script>
import LineChart from './chart'
export default {
components: {
LineChart
},
data () {
return {
datacollection: null
}
},
mounted () {
this.styling()
this.fillData()
},
methods: {
fillData () {
this.datacollection = {
labels: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()],
gridLines: {
display: false
},
datasets: [
{
label: 'Data One',
fill: false,
borderColor: 'red',
backgroundColor: 'red',
borderWidth: 1,
data: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()]
}
]
}
},
styling () {
this.Chart.defaults.global.elements.line.backgroundColor = '#1d3'
},
getRandomInt () {
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
}
}
}
</script>
The problem is :
it seems that I can't pass options whatsoever.
What I need to do is
Hide all gridlines inculding x&y
Make the tooltips always displayed
But I've tried every way possible and none of them works , even like :
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options'],
mounted () {
this.renderChart(this.chartData, {
scales: {
xAxes: [{
gridLines: {
color: "rgba(0, 0, 0, 0)",
display: false
}
}],
yAxes: [{
gridLines: {
color: "rgba(0, 0, 0, 0)",
display: false
}
}]
}
})
}
}
It won't work , tooltips is the same
I just want to know , is it possible for reactive vuechartjs to pass options ? or I just need to use chartjs instead ?
You can check demo at https://codepen.io/ittus/pen/MGQaNY
To make tooltips always display, you can add
Chart.pluginService.register({
beforeRender: function(chart) {
if (chart.config.options.showAllTooltips) {
chart.pluginTooltips = [];
chart.config.data.datasets.forEach(function(dataset, i) {
chart.getDatasetMeta(i).data.forEach(function(sector, j) {
chart.pluginTooltips.push(new Chart.Tooltip({
_chart: chart.chart,
_chartInstance: chart,
_data: chart.data,
_options: chart.options.tooltips,
_active: [sector]
}, chart));
});
}); // turn off normal tooltips
chart.options.tooltips.enabled = false;
}
},
afterDraw: function(chart, easing) {
if (chart.config.options.showAllTooltips) { // we don't want the permanent tooltips to animate, so don't do anything till the animation runs atleast once
if (!chart.allTooltipsOnce) {
if (easing !== 1) return;
chart.allTooltipsOnce = true;
}
chart.options.tooltips.enabled = true;
Chart.helpers.each(chart.pluginTooltips, function(tooltip) {
tooltip.initialize();
tooltip.update(); // we don't actually need this since we are not animating tooltips
tooltip.pivot();
tooltip.transition(easing).draw();
});
chart.options.tooltips.enabled = false;
}
}
});
then pass showAllTooltips: true into options

"TypeError: __WEBPACK_IMPORTED_MODULE_1_jsplumb___default.a.draggable is not a function"

I'm trying to do drag and drop using JsPlumb in vueJS. I used JsPlumb link and also imported jsplumb but it is not working. I'm getting error as
[Vue warn]: Error in created hook: "TypeError:
__WEBPACK_IMPORTED_MODULE_1_jsplumb___default.a.draggable is not a function"
This code is written inside the template
<div class="center_block">
<ul id="menu">
<li><img class="decision" src="../assets/images/symbol_decision.png" alt="human_gif"></li>
<li><img class="input" src="../assets/images/symbol_input1.png" alt="human_gif"></li>
</ul>
</div>
<div class="layout" id="layoutId" style="height:404px;"></div>
This code is written inside script
import jsPlumb from 'jsplumb'
export default {
name: 'HelloWorld',
data() {
return {
message: 'Welcome user',
endpoint1: '',
i: 0,
clone: '',
componentMap: {}
}
},
created() {
this.endpoint1 = {
isSource: true,
isTarget: true,
endpoint: ['Dot', {
radius: 4
}, {
outlineStroke: 'black'
}, {
outlineWidth: 10
}],
paintStyle: {
outlineStroke: 'black',
outlineWidth: 10
},
cssClass: 'ends',
maxConnections: -1,
connector: ['Flowchart', {
stub: [40, 60],
gap: 5,
cornerRadius: 5,
alwaysRespectStubs: true
}],
connectorStyle: {
strokeWidth: 2,
stroke: '#61B7CF'
},
connectorHoverClass: 'connector-line',
dropOptions: {
drop: function(e, ui) {
alert('drop!')
}
}
}
jsPlumb.draggable('decision', {
appendTo: 'body',
cursor: 'pointer',
containment: 'layoutId',
helper: 'clone',
revert: 'invalid'
})
window.jsPlumbInstance.droppable('layout', {
accept: '.decision, .input',
activeClass: 'ui-state-default',
hoverClass: 'ui-state-hover',
drop: function(event, ui) {
this.clone = ui.helper.clone()
this.clone.draggable({
containment: 'layout'
})
if (ui.draggable.attr('id') !== null) {
if (ui.draggable.attr('class').indexOf('decision') !== -1) {
this.clone.attr('id', 'input_' + this.i)
this.componentMap['input_' + this.i] = this.clone.attr('name')
jsPlumb.addEndpoint(this.clone, {
anchors: ['Left']
}, this.endpoint1)
jsPlumb.addEndpoint(this.clone, {
anchors: ['Right']
}, this.endpoint1)
}
}
}
})
}
}
can anyone please suggest me where I did the mistake?
I had the same issue and fixed it by importing jsPlumb this way:
import jsplum from 'jsplumb'
And then the calls should occurs like this:
jsplumb.jsPlumb.ready(function () {
jsplumb.jsPlumb.connect({
source: 'item0',
target: 'item1',
endpoint: 'Rectangle'
})
jsPlumb seems to be a non default export.
Do this:
import {jsPlumb} from 'jsplumb';