Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Is it possible to use a SFC Vue component as a mixin?

For example, I have a component written in SFC format:

// Parent.vue
<template>
  <div>
    {{ txt }}
  </div>
</template>

<script>
export default {
  name: 'ParentComponent',
  data() {
    return {
      txt: 'Hello, world! I\'m Parent'
    }
  },
  methods: {
    sayHello() {
      console.log(this.txt);
    }
  }
}
</script>

And I would like to reuse the component above from which I can extend:

// Child.vue
<template>
  <div>
    {{ txt }}
  </div>
</template>

<script>
import ParentComponent from './Parent';

export default {
  name: 'ChildComponent',
  mixins: [ParentComponent],
  created() {
    this.sayHello(); // 'Hello, world! I'm Parent'
  }
}
</script>

My questions:

  1. Is it possible to use like this fashion?
  2. If possible, then I can understand that the vue component properties like data, methods, ... will be integrated in ChildComponent as that is a basic behavior of Vue mixin. But what about <template> part? How the markup parts are integrated together? Or is it ignored so that the only <script> part is merged?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

1- Yes it's possible but using extends option instead of mixins :

<template>
  <div>
    {{ txt }}
  </div>
</template>

<script>
import ParentComponent from './Parent';

export default {
  name: 'ChildComponent',
  extends: ParentComponent,
  created() {
    this.sayHello(); 
  }
}
</script>

2 - This inherits only the extended component options.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!