Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b7a6de

Browse files
committed
🐛fixed sprite node attrs update bug
1 parent ac8bb28 commit 9b7a6de

File tree

5 files changed

+17
-64
lines changed

5 files changed

+17
-64
lines changed

dist/sprite-vue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36254,7 +36254,7 @@ function updateAttrs(oldVnode, vnode) {
3625436254
for (key in attrs) {
3625536255
cur = attrs[key];
3625636256
old = oldAttrs[key];
36257-
if (old !== cur) {
36257+
if (old !== cur || cur.__ob__) {
3625836258
setAttr(elm, key, cur);
3625936259
}
3626036260
}

dist/sprite-vue.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/test2.html

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,23 @@
2020
const { Vue } = spritevue
2121

2222
Vue.component('my-scene', {
23-
states() {
24-
return {
25-
active: {
26-
opacity: 1.0
27-
},
28-
deactive: {
29-
opacity: 0.2
30-
}
31-
}
32-
},
33-
actions: [
34-
{
35-
both: ['active', 'deactive'],
36-
action: {
37-
duration: 1000,
38-
easing: 'ease-in-out'
39-
}
40-
}
41-
],
4223
data () {
4324
return {
4425
viewport: [600, 600],
45-
text: 'Hello',
46-
items: [
47-
{ id: 'stop-btn', bgcolor: 'red', state: 'deactive' },
48-
{ id: 'warn-btn', bgcolor: '#fc0', state: 'deactive' },
49-
{ id: 'pass-btn', bgcolor: 'green', state: 'deactive' }
50-
],
51-
attrs: {
26+
ccc: {
5227
bgcolor: 'blue'
5328
}
5429
}
5530
},
56-
mounted() {
57-
console.log(this.$refs)
58-
},
59-
methods: {
60-
enter (index) {
61-
console.log('enter')
62-
this.items[index].state = 'active'
63-
},
64-
leave (index) {
65-
console.log('leave')
66-
this.items[index].state = 'deactive'
67-
},
68-
tap (index, evt) {
69-
console.log(index, evt)
70-
// this.$set(this.attrs, 'bgcolor', 'red')
71-
this.attrs.bgcolor = 'red'
72-
this.attrs = { ... this.attrs }
73-
},
74-
changed (evt) {
75-
console.log('state changed!', evt)
76-
}
31+
mounted () {
32+
// console.log(this.$refs)
33+
this.ccc.bgcolor = 'red'
34+
// this.attrs = { ... this.attrs }
7735
},
7836
template: `
7937
<scene id="container" :viewport=viewport>
8038
<layer id="fglayer">
81-
<group width="500" display="flex" y="100" justifyContent="space-between" bgcolor="grey">
82-
<sprite v-if="index < 2" v-for="(item, index) in items" :size="[50, 50]"
83-
:key="'sp'+index"
84-
ref="sp"
85-
:bgcolor="item.bgcolor"
86-
v-on:mouseenter="enter(index)"
87-
v-on:mouseleave="leave(index)"
88-
v-on:click="tap(index, $event)"
89-
:states="states" :actions="actions" :state="item.state"
90-
v-on:state-to-active="changed"></sprite>
91-
</group>
92-
<sprite :attrs="attrs" :size="[100, 100]" :pos="[200, 200]"></sprite>
39+
<sprite :attrs="ccc" :size="[100, 100]" :pos="[200, 200]"></sprite>
9340
</layer>
9441
</scene>
9542
`
@@ -100,8 +47,14 @@
10047
data() {
10148
return {
10249
state: true,
50+
attrs: {
51+
bg: 'background:blue'
52+
}
10353
};
10454
},
55+
mounted () {
56+
this.attrs.bg = 'background: red'
57+
},
10558
methods: {
10659
toggle() {
10760
console.log(111);
@@ -110,7 +63,7 @@
11063
},
11164
template: `
11265
<div>
113-
<h1 @click="toggle"> abc </h1>
66+
<h1 @click="toggle" :style="attrs.bg"> abc </h1>
11467
<div v-if="state">
11568
<my-scene></my-scene>
11669
</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sprite-vue",
3-
"version": "0.21.8",
3+
"version": "0.21.9",
44
"description": "A Vue.js project for SpriteJS",
55
"author": "akira-cn <[email protected]>",
66
"main": "src/index.js",

src/web/runtime/modules/attrs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
3737
for (key in attrs) {
3838
cur = attrs[key]
3939
old = oldAttrs[key]
40-
if (old !== cur) {
40+
if (old !== cur || cur.__ob__) {
4141
setAttr(elm, key, cur)
4242
}
4343
}

0 commit comments

Comments
 (0)