fritx / vue-at

At.js for Vue.
https://fritx.github.io/vue-at/
MIT License
529 stars 114 forks source link

EmbeddedItem is not working #98

Open prashanth4 opened 5 years ago

prashanth4 commented 5 years ago
<at :members="items" name-key="name" v-model="temp.test">
                  <span slot="embeddedItem" slot-scope="s">
                    <span class="tag" v-text="s.current.name "></span>
                  </span>
                  <div class="editor" contenteditable></div>
</at>
fritx commented 5 years ago

@prashanth4 is there any error threw or just no effect?

prashanth4 commented 5 years ago

Just no effect and also model value is also not working.

weiRongLady commented 5 years ago

I've met the question as you too. Have you solved it ?

lesharris commented 5 years ago

It needs a wrapping element to work. Vue-At uses the first child of the slot's root node. In @prashanth4's code the first child of the root node is an empty TEXT node.

To fix, simply add a wrapping element. It can be anything but I feel <span> is appropriate:

<template>
  <section>
    <at :members="items" name-key="name" v-model="temp.test">
      <template slot="embeddedItem" slot-scope="s">
        <!-- Wrap your element markup to fix -->
        <span>
          <span class="tag" v-text="s.current.name"></span>
        </span>
      </template>
      <div class="editor" contenteditable></div>
    </at>
  </section>
</template>

<script>
export default {
  name: "app",
  data() {
    return {
      temp: {
        test: ""
      },
      items: [{ name: "foo" }, { name: "bar" }, { name: "baz" }]
    };
  }
};
</script>

Example

johnsusek commented 4 years ago

FWIW, the install instructions installed 2.3.2 for me, which has this issue.

Updating to the latest (2.5.0-beta.2) fixed it.

fritx commented 4 years ago

@lesharris thanks for your comment!!

@johnsusek oops, it did !! Didn't remember to clarify in the docs that some new features require the latest beta (2.5.0-beta.2 for now)

Btw, is was an interesting behavior of npm, see below:

npm i vue-at          # => 2.5.0-beta.2
npm i vue-at@latest   # => 2.5.0-beta.2
npm i vue-at@2.x      # => 2.3.2 , which is documented nbow
npm i vue-at@2.5.x    # => error