I
I
Igor2019-10-30 17:03:09
Vue.js
Igor, 2019-10-30 17:03:09

Vue template in mixin?

Colleagues, good afternoon.
Can you mix a template?
The idea is the following.
progress_dialogs.js

export const progress_dialogs = {

  data() {
    return {
      progress_dialog_message: "",
      progress_dialog_visible: false,
    }
  },

  methods: {
    showProgressDialog(message) {
      this.progress_dialog_message = message
      this.progress_dialog_visible = true
    },

    hideProgressDialog() {
      this.progress_dialog_message = ""
      this.progress_dialog_visible = false
    },
  }
}

template
...
     // в некоторых шаблонах мне приходится дублировать вот это
    <progress-dialog
      :message="progress_dialog_message"
      :visible="progress_dialog_visible"
    />
  ...
  import {progress_dialogs} from "../../mixins/progress_dialogs"

Is it possible to do without forwarding this template, for example, something like this
Not a working option!
progress_dialogs.js
export const progress_dialogs = {

  template: `
    <progress-dialog
      :message="progress_dialog_message"
      :visible="progress_dialog_visible"
    />
  `
...
}

I just import the mixin and the desired template is mixed into the template

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin, 2019-10-30
@IgorPI

Why not just make this part of the template a separate component and reuse it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question