javascript - Vue 和 Vue-tippy html 内容

标签 javascript vuejs2

我需要在 vue-tippy 中显示一个 html 内容带有数据绑定(bind)元素的元素 ( https://github.com/KABBOUCHI/vue-tippy ),但它不起作用,

<div id="demo">
    <p>{{message}}</p>
    <br />
    <input v-model="message" title="Input">
    <br />
    Default example (it works)
    <button title="Hi!" v-tippy> My Button! </button>
    <br />
    Data binding example (it not works)
    <button title="{{ message }} " v-tippy> {{ message }} </button>
    <br />
    Data binding example (it works)
    <button :title="message" v-tippy> {{ message }} </button>

    <br />
    Data binding example  html content (it not works)
    <button id="button3" v-tippy data-html="#contentpopup"> {{ message }} -  html content </button>
    <br />
    <br />
    <div id="contentpopup" style="background:red;">
      <div>
         {{ message }} - My html content
      </div>
    </div>
    <br />
</div>

JS
var vueTippy = require('vue-tippy')
Vue.use(vueTippy)

var data = {
    message: 'Hello Vue.js!'
}

var demo = new Vue({
    el: '#demo',
    data: data
})

我怎样才能解决这个问题?

谢谢

最佳答案

我添加了对 HTML 模板和 Vue 组件的支持。

将 vue-tippy 包更新到最新版本,您的代码将正常工作。

例子:

new Vue({
  el: "#app",
  data() {
    return {
      message: 'Hello Vue.js!'
    }
  }
})
.btn {
  margin: 0;
  color: white;
  box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.12), 0 10px 36px -4px rgba(77, 96, 232, 0.3);
  background: -webkit-linear-gradient(315deg, #73a5ff, #5477f5);
  background: linear-gradient(135deg, #73a5ff, #5477f5);
  letter-spacing: 0.5px;
  font-family: inherit;
  display: inline-block;
  font-weight: 400;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  border: 1px solid transparent;
  padding: .5rem 1rem;
  font-size: 1rem;
  border-radius: .25rem;
  -webkit-transition: all .2s ease-in-out;
  -o-transition: all .2s ease-in-out;
  transition: all .2s ease-in-out;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.0/vue.min.js"></script>
<script src="https://kabbouchi.com/vue-tippy/vue-tippy.min.js"></script>

<div id="app">
  <button class="btn" v-tippy data-distance="15" data-theme="light" data-animation="scale" data-arrowsize="big" data-trigger="click" data-interactive="true" data-animatefill="false" data-arrow="true" data-html="#contentpopup">
    Popover HTML <small class="opacity-low">(click)</small>
  </button>
  <div id="contentpopup" style="display: none">
    <div>
      <h3> Header</h3>
      <p style="color: black"> {{ message }} - data binding </p>
    </div>
  </div>

</div>

关于javascript - Vue 和 Vue-tippy html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44365008/

相关文章:

javascript - 我需要在 jQuery 中使用 "e = e ? e : window.event;"吗?

javascript - 我应该如何使用凭证配置 AWS?

javascript - [Vue 警告] : Invalid prop: type check failed for prop "X". 预期,得到字符串

javascript - Object.getPrototypeOf() 与 .prototype

javascript - Vue 访问数组中的数组

javascript - Vue.js .我的方法中的函数未被识别

javascript - 如何通过数据获取元素-...具有指定值

javascript - 如何在 vue.js 2 上添加类?

javascript - Vue 组件 - 如何避免改变 prop(Laravel 组件)

vue.js - 对于 Vuex Store 中的每个项目,分配一个分数(基于计算),然后按分数排序