VueJS Mixins 方法直接调用

问题描述:

我正在 VueJS 上测试 Mixin,我有一个问题.有没有办法直接从 Mixins 调用事件而不必在我的 methods 中分配它?

I'm testing Mixins on VueJS and I have a question. Is there a way to call an event directly from a Mixins without having to assign it in my 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

app.vue

谢谢!

可以,直接调用即可.mixin 中的方法与它们混合"在一起的 Vue 或组件合并.它们可以像任何其他方法一样被调用.

解决方案