luddinus
473
2
Vue

Directive with template?

Posted 2 years ago by luddinus

Hi, I used to use Angular, so maybe what I want is not possible or I don't know yet.

I want to build a custom "directive" that appends (or prepends) some Html to the element given (a button with a spinner).

e.g:

<button v-button-spinner="saving">Save</button>

Two things I want.

  1. Add the spinner inside the "button" tag, something like this:
<template>
   <span>
      <i class="fa fa-spin fa-spinner" v-if="saving"></i><slot></slot>
   </span>
</template>
  1. Toggle the "disabled" attribute into the button (two way bind with "saving")

Any ideas? Probably is not that hard, but I think I still "poisoned" by Angular.

Thx.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.