最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can I set a dynamic tooltip in a select option using vue.js? - Stack Overflow

programmeradmin5浏览0评论

I have an array declared in vue.

sourceSelect: [
    { text: "Option 1", value: "1", title: "First tooltip" },
    { text: "Option 2", value: "2", title: "Second tooltip" },
    { text: "Option 3", value: "3", title: "Third tooltip" }
],

I have a select element in my markup:

<select class="form-group col-sm-8" v-on:change="showOptions" v-model="sourceSelected" data-toggle="tooltip" data-placement="top" data-html="true">
    <option v-for="source in sourceSelect" v-bind:value="source.value" title={{source.title}} >{{source.text}}</option>
</select>

The drop-down shows the options, and shows a tooltip, but unfortunately not the title values setup in the array - rather it shows {{source.title}}. Is there any way of setting up the values for a title attribute dynamically in this way? I'm using vue.2.6.10

I have an array declared in vue.

sourceSelect: [
    { text: "Option 1", value: "1", title: "First tooltip" },
    { text: "Option 2", value: "2", title: "Second tooltip" },
    { text: "Option 3", value: "3", title: "Third tooltip" }
],

I have a select element in my markup:

<select class="form-group col-sm-8" v-on:change="showOptions" v-model="sourceSelected" data-toggle="tooltip" data-placement="top" data-html="true">
    <option v-for="source in sourceSelect" v-bind:value="source.value" title={{source.title}} >{{source.text}}</option>
</select>

The drop-down shows the options, and shows a tooltip, but unfortunately not the title values setup in the array - rather it shows {{source.title}}. Is there any way of setting up the values for a title attribute dynamically in this way? I'm using vue.2.6.10

Share Improve this question edited Aug 21, 2020 at 14:50 Boussadjra Brahim 1 asked Aug 21, 2020 at 13:55 EdwardoEdwardo 9022 gold badges12 silver badges29 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You should bind as you did with value attribute :

 <option v-for="source in sourceSelect" v-bind:value="source.value"  v-bind:title="source.title" >{{source.text}}</option>

Vue.config.devtools = false;
Vue.config.productionTip = false;

new Vue({
  el: '#app',
  data() {
    return {
      sourceSelect: [{
          text: "Option 1",
          value: "1",
          title: "First tooltip"
        },
        {
          text: "Option 2",
          value: "2",
          title: "Second tooltip"
        },
        {
          text: "Option 3",
          value: "3",
          title: "Third tooltip"
        }
      ]
    }
  }
})
<link type="text/css" rel="stylesheet" href="//unpkg./bootstrap/dist/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare./ajax/libs/vue/2.5.16/vue.js"></script>


<div id="app" class="container">
  <select class="form-group col-sm-8" data-toggle="tooltip" data-placement="top" data-html="true">
    <option v-for="source in sourceSelect" v-bind:value="source.value" :title="source.title">{{source.text}}</option>
  </select>

</div>

发布评论

评论列表(0)

  1. 暂无评论