doumingo04696 2017-07-12 18:34
浏览 124
已采纳

Vue.js + PHP选择输入在提交时不会保留

My "issue" is actually ignorance. I have an HTML form and I use Vue.js to fill a v-select input with PHP data:

<div id="app">
    <form>
        <v-select name="user2_id" placeholder="Seleccionar Usuario" :options="[{!! $users !!}]" class="select"></v-select>
        <select name="user2_type" id="user2_type" class="form-control required">
        ...
        </select>
    </form>
</div>

The JS part:

<script src="https://unpkg.com/vue@2.1.10"></script>
<script src="https://unpkg.com/vue-select@2.0.0"></script>
<script>
    Vue.component('v-select', VueSelect.VueSelect);

    new Vue({
        el: '#app'
    });
</script>

When I submit the form I only got the user2_type but not the user2_id. I think is because the browser does not recognize v-select as a form input.

Is there any easy way or should I submit the form with AJAX or something else?

Thank you

Edit: Web Inspector generated HTML output

<div class="dropdown v-select select searchable" name="user2_id">
    <div type="button" class="dropdown-toggle clearfix">
        <input debounce="0" placeholder="Seleccionar Usuario" class="form-control" style="width: 100%;" type="search">
        <i role="presentation" class="open-indicator"></i>
        <div class="spinner" style="display: none;">
            Loading...
        </div>
    </div><!---->
</div>
  • 写回答

1条回答 默认 最新

  • duancoubeng5909 2017-07-12 19:03
    关注

    vue-select does not create an actual <select> field, as in Vue components any form submissions are typically processed via AJAX, not a standard <form> POST.

    You'll need to get the value out of the <v-select> - there are a couple of ways.

    • Use a onChange callback (see the docs) to update a field manually.
    • Use v-model to update a hidden field simultaneously with the value.
      <v-select v-model="user2_id"></v-select>
      <input type="hidden" v-model="user2_id">
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算