<p>在Vue项目中使用layui需要以下步骤:</p>
<ol>
<li>在index.html中引入layui的css和js文件</li>
</ol>
<pre><code class="language-html">&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.staticfile.org/layui/2.5.6/css/layui.min.css&quot;&gt;
&lt;script src=&quot;https://cdn.staticfile.org/layui/2.5.6/layui.min.js&quot;&gt;&lt;/script&gt;
</code></pre>
<ol start="2">
<li>在Vue组件中使用layui</li>
</ol>
<p>在Vue组件的<script>标签中引入layui,然后在mounted钩子函数中初始化layui组件。</p>
<pre><code class="language-html">&lt;template&gt;
  &lt;div&gt;
    &lt;button class=&quot;layui-btn&quot; @click=&quot;showMsg&quot;&gt;点击弹出消息框&lt;/button&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
import layui from 'layui'

export default {
  mounted() {
    layui.use(['layer'], function() {
      var layer = layui.layer;
      // 使用layer组件
      layer.msg('Hello Layer!');
    });
  },
  methods: {
    showMsg() {
      layui.use(['layer'], function() {
        var layer = layui.layer;
        layer.msg('Hello Layer!');
      });
    }
  }
}
&lt;/script&gt;
</code></pre>
<p>这样就可以在Vue项目中使用layui组件了。需要注意的是,layui的组件必须在初始化后才能使用,否则会出现错误</p>
vue项目如何使用layui

原文地址: https://www.cveoy.top/t/topic/dHM9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录