【发布时间】:2018-03-17 11:14:56
【问题描述】:
我正在 VueJS 上测试 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.js vuejs2 vue-component mixins