Here is an example :
mixin.js
export default {
methods : {
aFunction() { // Some functionality here }
}
}
ponent.vue
import mixin from './mixin'
export default {
mixins : [ mixin ]
created() {
// Call aFunction defined in the mixin here
}
}
I want to access the aFunction defined inside methods of mixin from the created() lifecycle method inside the ponent.
Here is an example :
mixin.js
export default {
methods : {
aFunction() { // Some functionality here }
}
}
ponent.vue
import mixin from './mixin'
export default {
mixins : [ mixin ]
created() {
// Call aFunction defined in the mixin here
}
}
I want to access the aFunction defined inside methods of mixin from the created() lifecycle method inside the ponent.
Share Improve this question asked Sep 25, 2017 at 20:04 Gaurav SarmaGaurav Sarma 2,2972 gold badges28 silver badges46 bronze badges1 Answer
Reset to default 9The mixin methods are merged with the current instance of the ponent, so it would just be:
created(){
this.aFunction()
}
Here is an example.
console.clear()
const mixin = {
methods:{
aFunction(){
console.log("called aFunction")
}
}
}
new Vue({
mixins:[mixin],
created(){
this.aFunction()
}
})
<script src="https://unpkg./[email protected]"></script>