You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Use an arrow function so that `this` is bound to the Vue instance. Alternatively, use a custom Vue directive on the `.grid-stack` container element: https://vuejs.org/v2/guide/custom-directive.html
56
+
grid.on("dragstop",(event,element)=>{
57
+
constnode=element.gridstackNode;
58
+
// `this` will only access your Vue instance if you used an arrow function, otherwise `this` binds to window scope. see https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/
59
+
info.value=`you just dragged node #${node.id} to ${node.x},${node.y} – good job!`;
60
+
});
61
+
});
62
+
63
+
functionaddNewWidget(){
64
+
constnode=items[count.value]||{
65
+
x: Math.round(12*Math.random()),
66
+
y: Math.round(5*Math.random()),
67
+
w: Math.round(1+3*Math.random()),
68
+
h: Math.round(1+3*Math.random()),
69
+
};
70
+
node.id=node.content=String(count.value++);
71
+
grid.addWidget(node);
72
+
}
73
+
36
74
return{
37
-
// grid: undefined, // <-- don't do that. see https://github.com/gridstack/gridstack.js/issues/1635
38
-
count: 0,
39
-
info: "",
75
+
info,
76
+
addNewWidget,
40
77
};
41
78
},
42
-
items: [
43
-
{x: 2,y: 1,h: 2},
44
-
{x: 2,y: 4,w: 3},
45
-
{x: 4,y: 2},
46
-
{x: 3,y: 1,h: 2},
47
-
{x: 0,y: 6,w: 2,h: 2}
48
-
],
79
+
49
80
watch: {
50
81
/**
51
82
* Clear the info text after a two second timeout. Clears previous timeout first.
52
83
*/
53
-
info: function(newVal,oldVal){
84
+
info: function(newVal){
54
85
if(newVal.length===0)return;
55
86
56
87
window.clearTimeout(this.timerId);
@@ -59,29 +90,6 @@ <h1>How to integrate GridStack.js with Vue.js</h1>
59
90
},2000);
60
91
},
61
92
},
62
-
mounted: function(){
63
-
// Provides access to the GridStack instance across the Vue component.
// Use an arrow function so that `this` is bound to the Vue instance. Alternatively, use a custom Vue directive on the `.grid-stack` container element: https://vuejs.org/v2/guide/custom-directive.html
67
-
this.grid.on("dragstop",(event,element)=>{
68
-
constnode=element.gridstackNode;
69
-
// `this` will only access your Vue instance if you used an arrow function, otherwise `this` binds to window scope. see https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/
70
-
this.info=`you just dragged node #${node.id} to ${node.x},${node.y} – good job!`;
0 commit comments