Rectangle 27 0

javascript How to bind an input tag inside a popover to Vue Model?


<popper trigger="click" :options="{placement: 'bottom'}">
  <div class="popper">
    <input type="text" v-model="message">
  </div>

  <div slot="reference" class="btn">
    Click Me!
  </div>  
</popper>

I found a useful Vue Package(vue-popper).

It do the same thing without using Bootstrap!

Note
Rectangle 27 0

javascript How to bind an input tag inside a popover to Vue Model?


<div id="vue-app">
    <div class="btn btn-primary" v-on:click="showPop = !showPop">Click Me!</div>
    <div class="mypopover" v-if="showPop">
        <p>Title</p>
        <input v-model="message">
     </div>
    <hr>
    <input v-model="message">
    {{ message }}
</div>
new Vue({   
    el:'#vue-app',
    data: {
        message: 'I am a Text',
        showPop: false
    }
 });

However, a more elegant solution (imho) is to create the basic Vue v-if function

Just apply the bootstrap css class for styling

Vue cannot just know of html-element you dynamically create, hence your created input-element cannot be bound. If you really want to solve it this way, I think the render function can help you: https://vuejs.org/v2/guide/render-function.html

Note
Rectangle 27 0

javascript How to bind an input tag inside a popover to Vue Model?


<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="https://unpkg.com/vue@2.4.2"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
</head>
<body>

<div id="vue-app">
  <div class="btn btn-primary" data-toggle="popover" data-placement="bottom" title="Hello World!" data-html="true">
    Click Me!
  </div>
  <hr>
  <input type="text" v-model="message"> {{ message }}

  <div id="popper-content" class="hide popper-content">
    <input type="text" v-model="message">
  </div>
</div>

</body>
</html>
new Vue({
  el:'#vue-app',
  data: {
    message: 'I am a Text!'
  }
})

$(document).ready(function(){
  $('[data-toggle="popover"]').popover({
    html: true,
    content: $('#popper-content')
  }).on('show.bs.popover', function() {
    $('#popper-content').addClass('show')
  }).on('hide.bs.popover', function() {
    $('#popper-content').addClass('hide')
  })
});

Nice one! Just a small recommendation that you can remove data-html="true" from the popover html, as in JS you are already specifying html:true .

This is not the most elegant solution since you are mixing two libaries here (Vue and Jquery). Vue itself can handle this by itself with much less code (using v-if)

You can remove html:true from js inside your code.

You can use like this:

Note