Skip to content

Commit d2f3831

Browse files
committed
Use more convenient way to await in vuejs, see vuejs feature request
vuejs/vue#10338
1 parent 54796b9 commit d2f3831

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

example-1.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
<div id="main">
1515

1616
<h3>{{ title }}</h3>
17-
<a @click="titleReverse2()" class="button">swap</a>
18-
<!--a @click="title = meth3(title)" class="button">swap</a-->
19-
<a @click="titleReverse3()" class="button">swap</a> <!-- all methods are async -->
17+
<a @click="(async()=> title = await meth2(title))" class="button">swap</a>
18+
<!--a @click.async="title = meth3(title)" class="button">swap</a-->
19+
<a @click="(async()=> title = await meth3(title))" class="button">swap</a> <!-- all methods are async -->
20+
<a @click="asyncSet('title', meth3(title))" class="button">swap</a> <!-- all methods are async -->
2021
<br/>
2122

2223
We can have a state in Python which is a counter "i".
@@ -61,12 +62,8 @@ <h3>{{ title }}</h3>
6162
}
6263
},
6364
methods: {
64-
async titleReverse2 () { // to my knowledge, we cannot do await directly in @click
65-
this.title = await this.meth2(this.title)
66-
},
67-
async titleReverse3 () { // to my knowledge, we cannot do await directly in @click
68-
this.title = await this.meth3(this.title)
69-
// ^^^^^ async even if in pyton it is a non-async method
65+
async asyncSet (attr, asyncVal) {
66+
this.$set(this, attr, await asyncVal)
7067
},
7168
}
7269
})

0 commit comments

Comments
 (0)