vue+layui实现select动态加载后台数据的例子

刚开始由于layui form渲染与vue渲染有时间差 有时会导致 select里面是空白的

后来就想办法 等vue数据渲染完 再渲染layui form

试过模块化导入layui form组件 然后等vue数据渲染完后手动进行渲染

这种方式有一个小问题 有时候会提示render方法未定义

可能是由于执行顺序原因 vue先执行了

最后把vue代码放到layui.use里面 问题解决

可能不是最好的实现方式 如有更好的实现方式欢迎指出 共同进步

页面代码

<div id=\"demo\" class=\"layui-inline layui-form\" lay-filter=\"test2\">
 <select>
  <option v-for=\"option in options\" v-bind:value=\"option.id\">
  {{ option.name }}
 </option> </select>
</div>

js

var vue = new Vue({
   el: \'#demo\',
   data: {
  option: {}, 
    options: []
   },
      created: function () {
         this.send();
      },
      updated: function () {
         layui.form.render(\'select\',\'test2\');
         console.log(layui.form);
      },
   methods:{
   send() {
    axios({
          method:\'get\',
          url:\'${contextPath}/find?page=1&limit=100\'
        }).then(resp => {
         this.options = resp.data.data;
          console.log(resp.data.data);        
        }).catch(resp => {
          console.log(\'请求失败:\'+resp.status+\',\'+resp.statusText);
        });
      } 
   },
  })

以上这篇vue+layui实现select动态加载后台数据的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容