Vueでのミックスインの使用

ミックスインの使用

ミックスインは通常、複数のコンポーネントに同じコードのパーツが含まれている場合に使用され、共通のパーツはミックスインミキサーに書き込まれてから、異なるコンポーネントにミックスされます。

export const mixin={
    
    
    methods:{
    
    
        add(){
    
    
            this.qqq++;
        }
    }
}
<template>
  <div>
    <button @click="add">+</button>
    {
   
   {qqq}}
  </div>
</template>

<script>
import {mixin} from "@/mixin";

export default {
  name: "cpna",
  mixins:[mixin],
  data(){
    return {
      qqq:0,
    }
  }
}
</script>

<style scoped>

</style>

おすすめ

転載: blog.csdn.net/lyyrhf/article/details/115217835
おすすめ