μλ
νμΈμ, μ λ vm.$dispatch
μ λν΄ μ½κ° νΌλμ€λ½μ΅λλ€. μλνλ©΄ μ½λ°± _(imo)_μ λ°°μΉν μ μλ μΆκ° λ
Όλ¦¬μ λν΄ λ¦¬μ€λμ μ½λ°±μμ κ°μ λ°νν κ²μΌλ‘ μμνκΈ° λλ¬Έμ
λλ€. μ€μ€λ‘λ₯Ό μλ‘ λ€ μ μμ΅λλ€. λλ Vueλ₯Ό λ°°μ°κ³ μμΌλ©° μλ§λ λκ°λ₯Ό λμ³€μ κ²μ
λλ€.
var vm = new Vue({
// omitted
events: {
'object:creating' : function (args) {
// omitted
return false;
},
'object:created' : function (args) {
// omitted
}
}
});
var child = new Vue({
parent: vm,
// omitted
methods: {
performWhatever: function (args) {
//
},
createObject: function (args) {
// Pre-create
if ( this.$dispatch('object:creating', args) === false ) {
// Stop the creation
}
// The business logic
this.performWhatever(args);
// Post-create
this.$dispatch('object:created', args);
}
}
})
보μλ€μνΌ μ¬μ μμ± μμ
μ μ ν μ¬νμ
λλ€.
κ°μ¬ν©λλ€.
SomeAsyncCode === false
$dispatch
λ μ½λ°± ν¨μλ₯Ό ν¬ν¨ν μ¬λ¬ μΈμλ₯Ό μ λ¬ν κ²μΌλ‘ μμν©λλ€.this.$dispatch('object:creating', args, function() {
// The business logic
this.performWhatever(args);
})
κ·Έλ¦¬κ³ μμ μ μΈ‘μμλ
events: {
'object:creating' : function (args, callback) {
// Do something with args and fire callback (or not)
callback()
}
}
@fnlctrl μ€λͺ κ°μ¬ν©λλ€ :)
@fnlctrl μ€λͺ κ°μ¬ν©λλ€. λΉλκΈ°μμ΄λΌ λΆλλ½λ€λ κ±Έ κΉλΉ‘νλ€ =D
κ°μ₯ μ μ©ν λκΈ
SomeAsyncCode === false
$dispatch
λ μ½λ°± ν¨μλ₯Ό ν¬ν¨ν μ¬λ¬ μΈμλ₯Ό μ λ¬ν κ²μΌλ‘ μμν©λλ€.κ·Έλ¦¬κ³ μμ μ μΈ‘μμλ