Skip to content

Commit 8f000a9

Browse files
committed
feat: add Vue 2.7 example
1 parent d53f327 commit 8f000a9

File tree

15 files changed

+5401
-1015
lines changed

15 files changed

+5401
-1015
lines changed

examples/vue2.7/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Local
2+
.DS_Store
3+
*.local
4+
*.log*
5+
6+
# Dist
7+
node_modules
8+
dist/
9+
10+
# IDE
11+
.vscode/*
12+
!.vscode/extensions.json
13+
.idea

examples/vue2.7/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Lock files
2+
package-lock.json
3+
pnpm-lock.yaml
4+
yarn.lock

examples/vue2.7/.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

examples/vue2.7/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rsbuild project
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
pnpm install
9+
```
10+
11+
## Get started
12+
13+
Start the dev server:
14+
15+
```bash
16+
pnpm dev
17+
```
18+
19+
Build the app for production:
20+
21+
```bash
22+
pnpm build
23+
```
24+
25+
Preview the production build locally:
26+
27+
```bash
28+
pnpm preview
29+
```

examples/vue2.7/eslint.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
4+
export default [
5+
{ languageOptions: { globals: globals.browser } },
6+
js.configs.recommended,
7+
{ ignores: ['dist/'] },
8+
];

examples/vue2.7/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "vue2.7",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "rsbuild build",
8+
"dev": "rsbuild dev --open",
9+
"format": "prettier --write .",
10+
"lint": "eslint .",
11+
"preview": "rsbuild preview"
12+
},
13+
"dependencies": {
14+
"element-ui": "^2.15.14",
15+
"vue": "^2.7.16",
16+
"vue-nice-modal": "2.1.1"
17+
},
18+
"devDependencies": {
19+
"@eslint/js": "^9.21.0",
20+
"@rsbuild/core": "^1.2.16",
21+
"@rsbuild/plugin-vue2": "^1.0.2",
22+
"eslint": "^9.21.0",
23+
"globals": "^16.0.0",
24+
"prettier": "^3.5.2"
25+
}
26+
}

examples/vue2.7/rsbuild.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginVue2 } from '@rsbuild/plugin-vue2';
3+
4+
export default defineConfig({
5+
plugins: [pluginVue2()],
6+
});

examples/vue2.7/src/App.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<NiceModalProvider>
3+
<Example />
4+
</NiceModalProvider>
5+
</template>
6+
7+
<script setup>
8+
import { Provider as NiceModalProvider } from 'vue-nice-modal';
9+
import Example from './Example.vue';
10+
</script>

examples/vue2.7/src/Example.vue

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<template>
2+
<div>
3+
<el-card header="推荐-基础用法 直接使用组件">
4+
<el-button @click="handleBasicClick">打开模态框</el-button>
5+
</el-card>
6+
7+
<el-button @click="handleDeclarationClick">打开模态框</el-button>
8+
9+
<!-- 声明式用法需要的模态框声明 -->
10+
<MyDialog id="declaration-modal" />
11+
12+
<el-card header="Hook 用法">
13+
<el-button @click="handleHookClick">打开模态框</el-button>
14+
</el-card>
15+
16+
<el-card header="注册 用法">
17+
<el-button @click="handleRegisterClick">打开模态框</el-button>
18+
</el-card>
19+
</div>
20+
</template>
21+
22+
<script setup>
23+
// 基础用法
24+
import NiceModal from 'vue-nice-modal';
25+
import { MyDialog } from './components/MyDialog';
26+
const handleBasicClick = async () => {
27+
try {
28+
const res = await NiceModal.show(MyDialog, {
29+
title: '基础用法',
30+
content: '直接使用组件方式调用模态框',
31+
});
32+
console.log('基础用法结果:', res);
33+
} catch (error) {
34+
console.log('基础用法取消:', error);
35+
}
36+
};
37+
38+
// 声明式用法
39+
const handleDeclarationClick = async () => {
40+
try {
41+
const res = await NiceModal.show('declaration-modal', {
42+
title: '声明式用法',
43+
content: '通过 ID 引用已在模板中声明的模态框',
44+
});
45+
console.log('声明式用法结果:', res);
46+
} catch (error) {
47+
console.log('声明式用法取消:', error);
48+
}
49+
};
50+
51+
// Hook 用法
52+
const hookModal = NiceModal.useModal(MyDialog);
53+
54+
const handleHookClick = async () => {
55+
try {
56+
const res = await hookModal.show({
57+
title: 'Hook 用法',
58+
content: '使用 useModal 组合式 API 调用模态框',
59+
});
60+
console.log('Hook 用法结果:', res);
61+
} catch (error) {
62+
console.log('Hook 用法取消:', error);
63+
}
64+
};
65+
66+
// 注册用法
67+
NiceModal.register('register-modal', MyDialog);
68+
const handleRegisterClick = async () => {
69+
try {
70+
const res = await NiceModal.show('register-modal', {
71+
title: '注册用法',
72+
content: '通过预先注册后使用 ID 调用模态框',
73+
});
74+
console.log('注册用法结果:', res);
75+
} catch (error) {
76+
console.log('注册用法取消:', error);
77+
}
78+
};
79+
</script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<el-dialog
3+
:title="title"
4+
:visible="modal.visible.value"
5+
width="30%"
6+
@close="handleCancel"
7+
@closed="modal.remove"
8+
>
9+
<span>这是一段信息 {{ content }}</span>
10+
<span slot="footer" class="dialog-footer">
11+
<el-button @click="handleCancel">取 消</el-button>
12+
<el-button type="primary" @click="handleConfirm">确 定</el-button>
13+
</span>
14+
</el-dialog>
15+
</template>
16+
<script setup>
17+
import { useModal } from 'vue-nice-modal';
18+
19+
const modal = useModal();
20+
defineProps(['title', 'content']);
21+
22+
const handleCancel = () => {
23+
modal.reject('cancel');
24+
modal.hide();
25+
};
26+
27+
const handleConfirm = () => {
28+
modal.resolve('confirm');
29+
modal.hide();
30+
};
31+
</script>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { create } from 'vue-nice-modal';
2+
import _MyDialog from './MyDialog.vue';
3+
4+
export const MyDialog = create(_MyDialog);

examples/vue2.7/src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Vue from 'vue';
2+
import ElementUI from 'element-ui';
3+
import 'element-ui/lib/theme-chalk/index.css';
4+
import App from './App.vue';
5+
6+
Vue.use(ElementUI, { size: 'small', zIndex: 3000 });
7+
Vue.config.productionTip = false;
8+
9+
new Vue({
10+
el: '#root',
11+
render: (h) => h(App),
12+
});

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
"devDependencies": {
1616
"husky": "^8.0.3",
1717
"lint-staged": "^13.2.2",
18-
"pnpm": "9.15.4",
18+
"pnpm": "9.15.5",
1919
"prettier": "^2.8.8",
2020
"prettier-plugin-packagejson": "^2.4.3"
2121
},
22-
"packageManager": "[email protected]"
22+
"packageManager": "[email protected]",
23+
"volta": {
24+
"node": "20.19.0",
25+
"pnpm": "9.15.5"
26+
}
2327
}

packages/vue-nice-modal/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"build": "rm -rf dist && npm run build:esm && npm run build:cjs && cp ./src/index.d.ts ./dist/index.d.ts",
4545
"build:cjs": "BUILD_FORMAT=cjs vite build",
4646
"build:esm": "BUILD_FORMAT=esm vite build",
47+
"prepare": "npm run build",
4748
"start": "npm run build:esm -- --watch",
4849
"test": "echo \"Error: no test specified\" && exit 1"
4950
},

0 commit comments

Comments
 (0)