layui/example/docs/zh-CN/guide/getStarted.md

128 lines
3.0 KiB
Markdown
Raw Normal View History

2021-10-25 17:13:23 +00:00
::: title 快速上手
:::
2022-02-25 05:17:06 +00:00
<br>
<p>
<a href="http://layui-vue.pearadmin.com" style="margin-left:30px;">
2022-03-28 16:44:21 +00:00
<img src="../../../src/assets/layui-logo.png" alt="layui" width="105" style="border-radius:12px;">
2022-02-25 05:17:06 +00:00
</a>
<span style="font-size:32px;color:#e2e2e2;margin:30px;">+</span>
2022-02-25 05:17:06 +00:00
<a href="http://layui-vue.pearadmin.com">
<img src="https://qn.antdv.com/vue.png" alt="layui" width="105" style="border-radius:12px;">
2022-02-25 05:17:06 +00:00
</a>
<span style="font-size:32px;color:#e2e2e2;margin:30px;">=</span>
2022-02-25 05:17:06 +00:00
<a href="http://layui-vue.pearadmin.com">
<img src="../../../src/assets/logo.jpg" alt="layui" width="105" style="border-radius:12px;">
2022-02-25 05:17:06 +00:00
</a>
</p>
<br>
2022-02-05 19:19:24 +00:00
2022-03-28 16:44:21 +00:00
::: title 使用包管理
:::
::: describe 使用 npm 工具安装 layui vue, 然后你可以使用打包工具, 如 vite rollup.
2022-02-07 05:42:38 +00:00
:::
2022-02-05 19:19:24 +00:00
2021-09-29 09:22:33 +00:00
```
2022-02-07 05:42:38 +00:00
npm install @layui/layui-vue --save
```
2022-01-29 02:50:44 +00:00
::: title 全局注册
2021-10-26 18:04:47 +00:00
:::
```js
import App from './App.vue'
import { createApp } from 'vue'
import Layui from '@layui/layui-vue'
2021-11-28 10:53:42 +00:00
import '@layui/layui-vue/lib/index.css'
createApp(App).use(Layui).mount('#app')
2021-09-30 19:03:24 +00:00
```
2022-02-07 05:42:38 +00:00
::: describe 以上代码便完成了 layui-vue 的引入。需要注意的是,样式文件需要单独引入。
:::
2021-10-19 14:28:44 +00:00
2022-01-29 02:50:44 +00:00
::: title 按需引入
:::
```js
import App from './App.vue'
import { createApp } from 'vue'
import { LayButton, LayTable } from '@layui/layui-vue'
import '@layui/layui-vue/es/button/index.css';
import '@layui/layui-vue/es/table/index.css';
var app = createApp(App).
app.component("LayButton", LayButton);
app.component("LayTable", LayTable);
app.mount('#app')
```
2022-01-29 02:55:40 +00:00
::: title 基础示例
2021-10-26 18:04:47 +00:00
:::
2021-09-30 19:03:24 +00:00
```html
<lay-layout>
<lay-header>
<lay-logo>Layui Admin</lay-logo>
</lay-header>
<lay-side></lay-side>
<lay-body>
<router-view></router-view>
</lay-body>
<lay-footer>pearadmin.com</lay-footer>
2021-09-30 19:03:24 +00:00
</lay-layout>
2021-10-07 16:17:34 +00:00
```
2022-03-28 16:44:21 +00:00
::: title 浏览器导入
2022-02-07 05:42:38 +00:00
:::
2022-03-28 16:44:21 +00:00
::: describe 根据不同的 CDN 提供商有不同的引入方式, 根据不同的 CDN 提供商有不同的引入方式, 我们在这里以 unpkg 举例。
:::
2022-03-31 11:05:08 +00:00
```html
2022-03-28 16:44:21 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 layui-vue 样式 -->
<link rel="stylesheet" type="text/css" href="https://unpkg.com/@layui/layui-vue/lib/index.css">
<!-- 引入 Vue 3, 使用全局变量 Vue -->
<script src="https://unpkg.com/vue@3"></script>
<!-- 引入 layui-vue 组件库, 使用全局变量 LayuiVue -->
<script src="https://unpkg.com/@layui/layui-vue"></script>
</head>
<body>
<div id="app">
<lay-button @click="sayHello">选项API</lay-button>
<lay-button @click="openLayer">组合API</lay-button>
</div>
</body>
<script>
const { createApp, ref } = Vue;
const { layer } = LayuiVue;
const App = {
setup() {
const openLayer = function () {
layer.msg("hello");
}
return {
openLayer
}
}
};
const app = createApp(App);
app.use(LayuiVue);
app.mount('#app');
</script>
</html>
```