vue项目如何使用layui
<p>在Vue项目中使用layui需要以下步骤:</p>
<ol>
<li>在index.html中引入layui的css和js文件</li>
</ol>
<pre><code class="language-html"><link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.6/css/layui.min.css">
<script src="https://cdn.staticfile.org/layui/2.5.6/layui.min.js"></script>
</code></pre>
<ol start="2">
<li>在Vue组件中使用layui</li>
</ol>
<p>在Vue组件的<script>标签中引入layui,然后在mounted钩子函数中初始化layui组件。</p>
<pre><code class="language-html"><template>
<div>
<button class="layui-btn" @click="showMsg">点击弹出消息框</button>
</div>
</template>
<script>
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!');
});
}
}
}
</script>
</code></pre>
<p>这样就可以在Vue项目中使用layui组件了。需要注意的是,layui的组件必须在初始化后才能使用,否则会出现错误</p>
原文地址: https://www.cveoy.top/t/topic/dHM9 著作权归作者所有。请勿转载和采集!