반응형
VueJS Mixins 메서드 다이렉트콜
VueJ에서 Mixins를 테스트하고 있는데 질문이 있습니다.Mixins에서 이벤트를 할당하지 않고 직접 호출할 수 있는 방법이 있습니까?methods
?
MyMixins.js
import Vue from 'vue'
Vue.mixin({
methods: {
Alerta(){
alert('WORK!')
}
}
})
app.vue
<template>
<button v-on:click="AlertaInterno">test</button>
</template>
<script>
export default{
methods:{
AlertaInterno(){
this.Alerta()
}
}
}
</script>
위의 코드는 동작한다.어떻게 하면 mixin 함수를 직접 호출할 수 있을까요?
app.vue
<template>
<button v-on:click="this.Alerta()">test</button>
</template>
감사합니다!
네, 직접 전화하시면 됩니다.혼합된 메서드는 Vue 또는 해당 메서드와 "혼합"된 구성 요소와 병합됩니다.그것들은 다른 방법들과 같은 방법으로 불릴 수 있다.
console.clear()
const Mixin = {
methods:{
Alerta(){
alert("WORK!")
}
}
}
new Vue({
mixins: [Mixin],
el: "#app"
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.min.js"></script>
<div id="app">
<button @click="Alerta">Alert!</button>
</div>
언급URL : https://stackoverflow.com/questions/46592331/vuejs-mixins-methods-direct-call
반응형
'itsource' 카테고리의 다른 글
MySQL 저장 루틴에 어레이 전달 (0) | 2022.09.06 |
---|---|
외부 키가 고유하지 않은 인덱스를 참조할 수 있습니까? (0) | 2022.09.06 |
GRANT가 MySQL에서 작동하지 않는 이유는 무엇입니까? (0) | 2022.09.05 |
모듈의 모든 기능을 나열하는 방법은 무엇입니까? (0) | 2022.09.05 |
String.split에서 파이프 딜리미터를 이스케이프해야 하는 이유는 무엇입니까? (0) | 2022.09.05 |