반응형
Vue.js의 컴포넌트 라이프 사이클 메서드에서 믹스인 메서드 내 기능에 액세스하는 방법
다음은 예를 제시하겠습니다.
mixin.displaces
export default {
methods : {
aFunction() { // Some functionality here }
}
}
요소.표시하다
import mixin from './mixin'
export default {
mixins : [ mixin ]
created() {
// Call aFunction defined in the mixin here
}
}
컴포넌트 내의 created() 라이프 사이클 메서드에서 mixin 메서드에 정의된 aFunction에 액세스하고 싶습니다.
mixin 메서드는 컴포넌트의 현재 인스턴스와 병합되므로 다음과 같습니다.
created(){
this.aFunction()
}
여기 예가 있습니다.
console.clear()
const mixin = {
methods:{
aFunction(){
console.log("called aFunction")
}
}
}
new Vue({
mixins:[mixin],
created(){
this.aFunction()
}
})
<script src="https://unpkg.com/vue@2.4.2"></script>
언급URL : https://stackoverflow.com/questions/46413319/how-to-access-function-inside-methods-of-mixin-from-component-lifecycle-method-i
반응형
'sourcecode' 카테고리의 다른 글
Vue 인라인 템플릿이 메서드 또는 데이터를 찾을 수 없음 (0) | 2022.08.13 |
---|---|
NDK 응용 프로그램에서 "인쇄" 메시지를 작성하려면 어떻게 해야 합니까? (0) | 2022.08.12 |
webpack-simple 설정 전송 오류와 함께 비동기/대기 사용: RegeneratorRuntime이 정의되지 않음 (0) | 2022.08.12 |
인터뷰 질문:한 문자열이 다른 문자열의 회전인지 확인합니다. (0) | 2022.08.12 |
Vue.js 2 - 하나의 애플리케이션/인스턴스 Vue에서 다른 애플리케이션/인스턴스 Vue로 $emit 이벤트를 발생시키는 방법 (0) | 2022.08.12 |