create-banana 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +10 -3
- package/.vscode/settings.json +10 -0
- package/bin/index.js +110 -35
- package/eslint.config.js +59 -0
- package/package.json +6 -2
- package/readme.md +6 -1
- package/template/Eslint/eslint.config.js.ejs +70 -31
- package/template/Eslint/package.json +1 -2
- package/template/Prettier/.prettierrc +1 -1
- package/template/Prettier/package.json +2 -2
- package/template/base/src/App.vue.ejs +119 -48
- package/template/base/src/components/HelloWorld.vue +1 -1
- package/template/base/src/components/TheWelcome.vue +61 -26
- package/template/base/src/components/icons/IconCommunity.vue +6 -1
- package/template/base/src/components/icons/IconDocumentation.vue +6 -1
- package/template/base/src/components/icons/IconEcosystem.vue +6 -1
- package/template/base/src/components/icons/IconSupport.vue +6 -1
- package/template/base/src/main.js.ejs +12 -1
- package/template/base/vite.config.js +5 -5
- package/template/pinia/counter.js +7 -7
- package/template/pinia/pinia-plugin-persistedstate/key.js +6 -6
- package/template/vue-router/components/TitleText.vue +13 -0
- package/template/vue-router/package.json +5 -0
- package/template/vue-router/router/index.js +32 -0
- package/template/vue-router/views/AboutView.vue.ejs +21 -0
- package/template/vue-router/views/HomeView.vue +7 -0
- package/template/vue-router/views/NotFound.vue +7 -0
- package/utils/URL.js +9 -7
- package/utils/figletPrint.js +6 -6
- package/utils/pathExists.js +13 -11
- package/utils/rainbow.js +17 -12
- package/utils/template/base/appVue.js +25 -13
- package/utils/template/base/base.js +12 -12
- package/utils/template/base/main.js +25 -13
- package/utils/template/eslint/eslint.js +16 -19
- package/utils/template/eslint/eslintConfig.js +14 -11
- package/utils/template/pinia/pinia.js +20 -12
- package/utils/template/pinia/piniaPluginPersistedstate.js +24 -13
- package/utils/template/prettier.js +19 -20
- package/utils/template/vueRouter/aboutView.js +29 -0
- package/utils/template/vueRouter/vueRouter.js +46 -0
- package/eslint.config.mjs +0 -27
- package/template/Eslint/.eslintignore +0 -36
- package/template/Prettier/.prettierignore +0 -7
- package/template/base/.vscode/extensions.json +0 -3
package/.prettierrc
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
2
|
+
"printWidth": 80,
|
|
3
|
+
"tabWidth": 2,
|
|
4
|
+
"useTabs": false,
|
|
5
|
+
"semi": true,
|
|
4
6
|
"singleQuote": true,
|
|
5
|
-
"
|
|
7
|
+
"quoteProps": "as-needed",
|
|
8
|
+
"jsxSingleQuote": false,
|
|
9
|
+
"trailingComma": "es5",
|
|
10
|
+
"bracketSpacing": true,
|
|
11
|
+
"bracketSameLine": false,
|
|
12
|
+
"arrowParens": "always",
|
|
6
13
|
"endOfLine": "auto"
|
|
7
14
|
}
|
package/bin/index.js
CHANGED
|
@@ -1,63 +1,138 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import printString from '#utils/figletPrint.js'
|
|
3
|
-
import rainbowGradient from '#utils/rainbow.js'
|
|
4
|
-
import { input } from '@inquirer/prompts'
|
|
5
|
-
import createBaseProject from '#utils/template/base/base.js'
|
|
6
|
-
import { checkbox } from '@inquirer/prompts'
|
|
7
|
-
import addEslint from '#utils/template/eslint/eslint.js'
|
|
8
|
-
import addPrettier from '#utils/template/prettier.js'
|
|
9
|
-
import addEslintConfig from '#utils/template/eslint/eslintConfig.js'
|
|
10
|
-
import addPinia from '#utils/template/pinia/pinia.js'
|
|
11
|
-
import addAppVue from '#utils/template/base/appVue.js'
|
|
12
|
-
import path from 'path'
|
|
13
|
-
import confirmPathExists from '#utils/pathExists.js'
|
|
14
|
-
import addMain from '#utils/template/base/main.js'
|
|
15
|
-
import { select } from '@inquirer/prompts'
|
|
16
|
-
import addPiniaPluginPersistedstate from '#utils/template/pinia/piniaPluginPersistedstate.js'
|
|
2
|
+
import printString from '#utils/figletPrint.js';
|
|
3
|
+
import rainbowGradient from '#utils/rainbow.js';
|
|
4
|
+
import { input } from '@inquirer/prompts';
|
|
5
|
+
import createBaseProject from '#utils/template/base/base.js';
|
|
6
|
+
import { checkbox } from '@inquirer/prompts';
|
|
7
|
+
import addEslint from '#utils/template/eslint/eslint.js';
|
|
8
|
+
import addPrettier from '#utils/template/prettier.js';
|
|
9
|
+
import addEslintConfig from '#utils/template/eslint/eslintConfig.js';
|
|
10
|
+
import addPinia from '#utils/template/pinia/pinia.js';
|
|
11
|
+
import addAppVue from '#utils/template/base/appVue.js';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import confirmPathExists from '#utils/pathExists.js';
|
|
14
|
+
import addMain from '#utils/template/base/main.js';
|
|
15
|
+
import { select } from '@inquirer/prompts';
|
|
16
|
+
import addPiniaPluginPersistedstate from '#utils/template/pinia/piniaPluginPersistedstate.js';
|
|
17
|
+
import chalk from 'chalk';
|
|
18
|
+
import boxen from 'boxen';
|
|
19
|
+
import addVueRouter from '#utils/template/vueRouter/vueRouter.js';
|
|
20
|
+
import addAboutView from '#utils/template/vueRouter/aboutView.js';
|
|
17
21
|
|
|
18
22
|
// print BANANA in rainbow colors
|
|
19
|
-
console.log
|
|
23
|
+
const log = console.log;
|
|
24
|
+
log(rainbowGradient(await printString('BANANA')));
|
|
20
25
|
|
|
21
|
-
const projectName = await input({
|
|
26
|
+
const projectName = await input({
|
|
27
|
+
message: `Enter your ${chalk.yellow('project name')}:`,
|
|
28
|
+
required: true,
|
|
29
|
+
});
|
|
22
30
|
|
|
23
31
|
// 确认路径存在
|
|
24
|
-
await confirmPathExists(projectName, path.join(process.cwd(), projectName))
|
|
32
|
+
await confirmPathExists(projectName, path.join(process.cwd(), projectName));
|
|
25
33
|
|
|
26
34
|
const feats = await checkbox({
|
|
27
|
-
message:
|
|
35
|
+
message: `Please select the ${chalk.yellow('features')} to include:`,
|
|
28
36
|
choices: [
|
|
29
37
|
{ name: 'Eslint', value: 'eslint' },
|
|
30
38
|
{ name: 'Prettier', value: 'prettier' },
|
|
31
39
|
{ name: 'Pinia', value: 'pinia' },
|
|
40
|
+
{ name: 'Vue-Router', value: 'vue-router' },
|
|
32
41
|
],
|
|
33
|
-
})
|
|
42
|
+
});
|
|
34
43
|
|
|
35
|
-
const useEslint = feats.includes('eslint')
|
|
36
|
-
const usePrettier = feats.includes('prettier')
|
|
37
|
-
const usePinia = feats.includes('pinia')
|
|
44
|
+
const useEslint = feats.includes('eslint');
|
|
45
|
+
const usePrettier = feats.includes('prettier');
|
|
46
|
+
const usePinia = feats.includes('pinia');
|
|
47
|
+
const useVueRouter = feats.includes('vue-router');
|
|
38
48
|
|
|
39
|
-
let usePiniaPluginPersistedstate = false
|
|
49
|
+
let usePiniaPluginPersistedstate = false;
|
|
40
50
|
if (usePinia) {
|
|
41
51
|
usePiniaPluginPersistedstate = await select({
|
|
42
|
-
message: `Do you want to use pinia-plugin-persistedstate for Pinia state persistence?`,
|
|
52
|
+
message: `Do you want to use ${chalk.yellow.bold('pinia-plugin-persistedstate')} for Pinia state persistence?`,
|
|
43
53
|
choices: [
|
|
44
54
|
{ name: 'Yes', value: true },
|
|
45
55
|
{ name: 'No', value: false },
|
|
46
56
|
],
|
|
47
|
-
})
|
|
57
|
+
});
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
// TODO: 把一类型的功能整合到一起
|
|
51
|
-
await createBaseProject(projectName)
|
|
52
|
-
await addAppVue(
|
|
53
|
-
|
|
61
|
+
await createBaseProject(projectName);
|
|
62
|
+
await addAppVue(
|
|
63
|
+
projectName,
|
|
64
|
+
usePinia,
|
|
65
|
+
usePiniaPluginPersistedstate,
|
|
66
|
+
useVueRouter
|
|
67
|
+
);
|
|
68
|
+
await addMain(
|
|
69
|
+
projectName,
|
|
70
|
+
usePinia,
|
|
71
|
+
usePiniaPluginPersistedstate,
|
|
72
|
+
useVueRouter
|
|
73
|
+
);
|
|
54
74
|
|
|
55
|
-
await addPinia(projectName, usePinia, usePiniaPluginPersistedstate)
|
|
56
|
-
await addPiniaPluginPersistedstate(projectName, usePiniaPluginPersistedstate)
|
|
75
|
+
await addPinia(projectName, usePinia, usePiniaPluginPersistedstate);
|
|
76
|
+
await addPiniaPluginPersistedstate(projectName, usePiniaPluginPersistedstate);
|
|
57
77
|
|
|
58
|
-
await addEslint(projectName, useEslint)
|
|
59
|
-
await addEslintConfig(projectName, usePrettier, useEslint)
|
|
78
|
+
await addEslint(projectName, useEslint);
|
|
79
|
+
await addEslintConfig(projectName, usePrettier, useEslint);
|
|
60
80
|
|
|
61
|
-
await addPrettier(projectName,
|
|
81
|
+
await addPrettier(projectName, usePrettier);
|
|
62
82
|
|
|
63
|
-
|
|
83
|
+
await addVueRouter(projectName, useVueRouter);
|
|
84
|
+
await addAboutView(projectName, usePiniaPluginPersistedstate, useVueRouter);
|
|
85
|
+
|
|
86
|
+
// 参考create-vue的颜色
|
|
87
|
+
const greenColor = [22, 198, 12];
|
|
88
|
+
|
|
89
|
+
// 安装依赖以及格式化提示
|
|
90
|
+
log(
|
|
91
|
+
rainbowGradient(
|
|
92
|
+
'\nProject initialization complete. You may now execute the following commands:\n'
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const eslintStr = chalk.rgb(...greenColor)(
|
|
97
|
+
`\n cd ${projectName} && pnpm i && pnpm lint && pnpm dev \n`
|
|
98
|
+
);
|
|
99
|
+
const prettierStr = chalk.rgb(...greenColor)(
|
|
100
|
+
`\n cd ${projectName} && pnpm i && pnpm format && pnpm dev \n`
|
|
101
|
+
);
|
|
102
|
+
const noFormatStr = chalk.rgb(...greenColor)(
|
|
103
|
+
`\n cd ${projectName} && pnpm i && pnpm dev \n`
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
let outStr = '';
|
|
107
|
+
useEslint
|
|
108
|
+
? (outStr = eslintStr)
|
|
109
|
+
: usePrettier
|
|
110
|
+
? (outStr = prettierStr)
|
|
111
|
+
: (outStr = noFormatStr);
|
|
112
|
+
|
|
113
|
+
log(
|
|
114
|
+
chalk.cyan(
|
|
115
|
+
boxen(outStr, {
|
|
116
|
+
title: 'commands',
|
|
117
|
+
titleAlignment: 'center',
|
|
118
|
+
})
|
|
119
|
+
),
|
|
120
|
+
'\n'
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// 初始化Git
|
|
124
|
+
log(rainbowGradient('Initialize Git using the following command:\n'));
|
|
125
|
+
// TODO: 以后有commitizen再改这里
|
|
126
|
+
log(
|
|
127
|
+
chalk.cyan(
|
|
128
|
+
boxen(
|
|
129
|
+
chalk.rgb(...greenColor)(
|
|
130
|
+
'\n git init && git add . && git commit -m "Initial commit" \n'
|
|
131
|
+
),
|
|
132
|
+
{
|
|
133
|
+
title: 'commands',
|
|
134
|
+
titleAlignment: 'center',
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
);
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import pluginVue from 'eslint-plugin-vue';
|
|
4
|
+
import json from '@eslint/json';
|
|
5
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
6
|
+
|
|
7
|
+
import prettierPlugin from 'eslint-plugin-prettier';
|
|
8
|
+
import prettierConfig from 'eslint-config-prettier';
|
|
9
|
+
|
|
10
|
+
export default defineConfig([
|
|
11
|
+
{
|
|
12
|
+
files: ['**/*.{js,mjs,cjs,vue}'],
|
|
13
|
+
plugins: { js },
|
|
14
|
+
extends: ['js/recommended'],
|
|
15
|
+
languageOptions: { globals: globals.node },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
files: ['**/*.vue'],
|
|
19
|
+
plugins: { vue: pluginVue },
|
|
20
|
+
extends: [pluginVue.configs['flat/essential']],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
files: ['**/*.json'],
|
|
24
|
+
plugins: { json },
|
|
25
|
+
language: 'json/json',
|
|
26
|
+
extends: ['json/recommended'],
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
// 全局 Prettier 配置
|
|
30
|
+
{
|
|
31
|
+
plugins: { prettier: prettierPlugin },
|
|
32
|
+
extends: [prettierConfig],
|
|
33
|
+
rules: {
|
|
34
|
+
'prettier/prettier': ['warn'], // 不符合 prettier 风格时显示 warning
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
globalIgnores([
|
|
39
|
+
'node_modules/*',
|
|
40
|
+
'dist/*',
|
|
41
|
+
'build/*',
|
|
42
|
+
'out/*',
|
|
43
|
+
'.next/*',
|
|
44
|
+
'.nuxt/*',
|
|
45
|
+
'coverage/*',
|
|
46
|
+
'public/*',
|
|
47
|
+
'assets/*',
|
|
48
|
+
'.cache/*',
|
|
49
|
+
'.temp/*',
|
|
50
|
+
'.tmp/*',
|
|
51
|
+
'*.min.js',
|
|
52
|
+
'*.bundle.js',
|
|
53
|
+
'package-lock.json',
|
|
54
|
+
'yarn.lock',
|
|
55
|
+
'pnpm-lock.yaml',
|
|
56
|
+
'.env*',
|
|
57
|
+
'docs/.vitepress/dist/*',
|
|
58
|
+
]),
|
|
59
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-banana",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/TMname1/create-banana.git"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@inquirer/prompts": "^8.1.0",
|
|
30
|
+
"boxen": "^8.0.1",
|
|
30
31
|
"chalk": "^5.6.2",
|
|
31
32
|
"ejs": "^3.1.10",
|
|
32
33
|
"figlet": "^1.9.4",
|
|
@@ -37,7 +38,9 @@
|
|
|
37
38
|
"@eslint/json": "^0.14.0",
|
|
38
39
|
"cz-conventional-changelog": "^3.3.0",
|
|
39
40
|
"eslint": "^9.39.2",
|
|
41
|
+
"eslint-config-prettier": "^10.1.8",
|
|
40
42
|
"eslint-plugin-prettier": "^5.5.4",
|
|
43
|
+
"eslint-plugin-vue": "^10.6.2",
|
|
41
44
|
"globals": "^16.5.0",
|
|
42
45
|
"husky": "^8.0.0",
|
|
43
46
|
"lint-staged": "^16.2.7",
|
|
@@ -51,7 +54,8 @@
|
|
|
51
54
|
"scripts": {
|
|
52
55
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
53
56
|
"commit": "cz",
|
|
54
|
-
"
|
|
57
|
+
"lint": "eslint . --fix --cache",
|
|
58
|
+
"format": "prettier --write --experimental-cli .",
|
|
55
59
|
"lint-staged": "lint-staged"
|
|
56
60
|
}
|
|
57
61
|
}
|
package/readme.md
CHANGED
|
@@ -4,36 +4,75 @@ import pluginVue from 'eslint-plugin-vue'
|
|
|
4
4
|
import json from '@eslint/json'
|
|
5
5
|
import markdown from '@eslint/markdown'
|
|
6
6
|
import css from '@eslint/css'
|
|
7
|
-
import { defineConfig } from 'eslint/config'
|
|
8
|
-
<% if(usePrettier) { %>
|
|
7
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
8
|
+
<% if (usePrettier) { %>
|
|
9
|
+
import prettierPlugin from 'eslint-plugin-prettier'
|
|
10
|
+
import prettierConfig from "eslint-config-prettier";
|
|
11
|
+
<% } %>
|
|
9
12
|
|
|
10
13
|
export default defineConfig([
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
]
|
|
14
|
+
{
|
|
15
|
+
files: ['**/*.{js,mjs,cjs,vue}'],
|
|
16
|
+
plugins: { js },
|
|
17
|
+
extends: ['js/recommended'],
|
|
18
|
+
languageOptions: { globals: globals.browser },
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
files: ["**/*.vue"],
|
|
22
|
+
plugins: { vue: pluginVue },
|
|
23
|
+
extends: [pluginVue.configs["flat/essential"]],
|
|
24
|
+
},
|
|
25
|
+
{ files: ['**/*.json'], plugins: { json }, language: 'json/json', extends: ['json/recommended'] },
|
|
26
|
+
{
|
|
27
|
+
files: ['**/*.jsonc'],
|
|
28
|
+
plugins: { json },
|
|
29
|
+
language: 'json/jsonc',
|
|
30
|
+
extends: ['json/recommended'],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
files: ['**/*.json5'],
|
|
34
|
+
plugins: { json },
|
|
35
|
+
language: 'json/json5',
|
|
36
|
+
extends: ['json/recommended'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
files: ['**/*.md'],
|
|
40
|
+
plugins: { markdown },
|
|
41
|
+
language: 'markdown/gfm',
|
|
42
|
+
extends: ['markdown/recommended'],
|
|
43
|
+
},
|
|
44
|
+
{ files: ['**/*.css'], plugins: { css }, language: 'css/css', extends: ['css/recommended'] },
|
|
45
|
+
|
|
46
|
+
<% if (usePrettier) { %>
|
|
47
|
+
// 全局 Prettier 配置
|
|
48
|
+
{
|
|
49
|
+
plugins: { prettier: prettierPlugin },
|
|
50
|
+
extends: [prettierConfig],
|
|
51
|
+
rules: {
|
|
52
|
+
'prettier/prettier': ['warn'], // 不符合 prettier 风格时显示 warning
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
<% } %>
|
|
56
|
+
|
|
57
|
+
globalIgnores([
|
|
58
|
+
"node_modules/*",
|
|
59
|
+
"dist/*",
|
|
60
|
+
"build/*",
|
|
61
|
+
"out/*",
|
|
62
|
+
".next/*",
|
|
63
|
+
".nuxt/*",
|
|
64
|
+
"coverage/*",
|
|
65
|
+
"public/*",
|
|
66
|
+
"assets/*",
|
|
67
|
+
".cache/*",
|
|
68
|
+
".temp/*",
|
|
69
|
+
".tmp/*",
|
|
70
|
+
"*.min.js",
|
|
71
|
+
"*.bundle.js",
|
|
72
|
+
"package-lock.json",
|
|
73
|
+
"yarn.lock",
|
|
74
|
+
"pnpm-lock.yaml",
|
|
75
|
+
".env*",
|
|
76
|
+
"docs/.vitepress/dist/*",
|
|
77
|
+
]),
|
|
78
|
+
])
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"scripts": {
|
|
3
|
-
"format": "prettier --write
|
|
4
|
-
"format:check": "prettier --check ."
|
|
3
|
+
"format": "prettier --write --experimental-cli src/"
|
|
5
4
|
},
|
|
6
5
|
"devDependencies": {
|
|
7
6
|
"eslint-config-prettier": "^10.1.8",
|
|
7
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
8
8
|
"prettier": "3.7.4"
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import HelloWorld from './components/HelloWorld.vue'
|
|
3
|
-
import TheWelcome from './components/TheWelcome.vue'
|
|
4
|
-
<% if(usePinia) { %>
|
|
5
|
-
|
|
2
|
+
import HelloWorld from './components/HelloWorld.vue'
|
|
3
|
+
import TheWelcome from './components/TheWelcome.vue'
|
|
4
|
+
<% if(usePinia) { %>
|
|
5
|
+
import {
|
|
6
|
+
useCounterStore
|
|
7
|
+
} from './stores/counter'
|
|
8
|
+
<% } %>
|
|
9
|
+
<% if(usePiniaPluginPersistedstate) { %>
|
|
10
|
+
import {
|
|
11
|
+
useKeyStore
|
|
12
|
+
} from './stores/key'
|
|
13
|
+
<% } %>
|
|
14
|
+
<% if(useVueRouter) { %>import {
|
|
15
|
+
useRoute
|
|
16
|
+
}
|
|
17
|
+
from 'vue-router'
|
|
18
|
+
<% } %>
|
|
6
19
|
|
|
7
|
-
<% if(usePinia) { %>
|
|
8
|
-
|
|
20
|
+
<% if(usePinia) { %>
|
|
21
|
+
const counterStore = useCounterStore()
|
|
22
|
+
<% } %>
|
|
23
|
+
<% if(usePiniaPluginPersistedstate) { %>
|
|
24
|
+
const keyStore = useKeyStore()
|
|
25
|
+
<% } %>
|
|
26
|
+
<% if(useVueRouter) { %>
|
|
27
|
+
const route = useRoute()
|
|
28
|
+
<% } %>
|
|
9
29
|
</script>
|
|
10
30
|
|
|
11
31
|
<template>
|
|
@@ -14,62 +34,113 @@ import TheWelcome from './components/TheWelcome.vue'
|
|
|
14
34
|
|
|
15
35
|
<div class="wrapper">
|
|
16
36
|
<HelloWorld msg="You did it!" />
|
|
17
|
-
<% if(usePinia) { %><button class="piniaBtn" @click="counterStore.increment">Count is:
|
|
37
|
+
<% if(usePinia) { %><button class="piniaBtn" @click="counterStore.increment">Count is:
|
|
38
|
+
{{ counterStore.count }}</button><% } %>
|
|
18
39
|
<% if(usePiniaPluginPersistedstate) { %><input class="persistInp" v-model="keyStore.key" placeholder="Enter a key to persist" /><% } %>
|
|
40
|
+
<% if(useVueRouter) { %>
|
|
41
|
+
<!-- 按钮切换页面 -->
|
|
42
|
+
<div>
|
|
43
|
+
<button class="routerBtn">
|
|
44
|
+
<router-link to="/home">
|
|
45
|
+
<span :class="{ 'active-link': route.name === 'home' }">
|
|
46
|
+
Home
|
|
47
|
+
</span>
|
|
48
|
+
</router-link>
|
|
49
|
+
</button>
|
|
50
|
+
<span style="margin: 0 5px">|</span>
|
|
51
|
+
<button class="routerBtn">
|
|
52
|
+
<router-link to="/about">
|
|
53
|
+
<span :class="{ 'active-link': route.name === 'about' }">
|
|
54
|
+
About
|
|
55
|
+
</span>
|
|
56
|
+
</router-link>
|
|
57
|
+
</button>
|
|
58
|
+
</div><% } %>
|
|
19
59
|
</div>
|
|
20
60
|
</header>
|
|
21
61
|
|
|
22
62
|
<main>
|
|
63
|
+
<% if(useVueRouter) { %>
|
|
64
|
+
<router-view />
|
|
65
|
+
<% } %>
|
|
66
|
+
<% if(!useVueRouter) { %>
|
|
23
67
|
<TheWelcome />
|
|
68
|
+
<% } %>
|
|
24
69
|
</main>
|
|
25
70
|
</template>
|
|
26
71
|
|
|
27
72
|
<style scoped>
|
|
28
|
-
header {
|
|
29
|
-
line-height: 1.5;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.logo {
|
|
33
|
-
display: block;
|
|
34
|
-
margin: 0 auto 2rem;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
<% if(usePinia) { %>.piniaBtn {
|
|
38
|
-
margin-top: 1rem;
|
|
39
|
-
padding: 0.5rem 1rem;
|
|
40
|
-
font-size: 1rem;
|
|
41
|
-
border: none;
|
|
42
|
-
border-radius: 4px;
|
|
43
|
-
background-color: #42b983;
|
|
44
|
-
color: white;
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
}<% } %>
|
|
47
|
-
|
|
48
|
-
<% if(usePiniaPluginPersistedstate) { %>.persistInp {
|
|
49
|
-
margin-top: 1rem;
|
|
50
|
-
padding: 0.5rem;
|
|
51
|
-
font-size: 1rem;
|
|
52
|
-
border: 1px solid #ccc;
|
|
53
|
-
border-radius: 4px;
|
|
54
|
-
width: 100%;
|
|
55
|
-
max-width: 300px;
|
|
56
|
-
}<% } %>
|
|
57
|
-
|
|
58
|
-
@media (min-width: 1024px) {
|
|
59
73
|
header {
|
|
60
|
-
|
|
61
|
-
place-items: center;
|
|
62
|
-
padding-right: calc(var(--section-gap) / 2);
|
|
74
|
+
line-height: 1.5;
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
.logo {
|
|
66
|
-
|
|
78
|
+
display: block;
|
|
79
|
+
margin: 0 auto 2rem;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
<% if(usePinia) {
|
|
83
|
+
%>.piniaBtn {
|
|
84
|
+
margin-top: 1rem;
|
|
85
|
+
padding: 0.5rem 1rem;
|
|
86
|
+
font-size: 1rem;
|
|
87
|
+
border: none;
|
|
88
|
+
border-radius: 4px;
|
|
89
|
+
background-color: #42b983;
|
|
90
|
+
color: white;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
<%
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
%><% if(usePiniaPluginPersistedstate) {
|
|
98
|
+
%>.persistInp {
|
|
99
|
+
margin-top: 1rem;
|
|
100
|
+
padding: 0.5rem;
|
|
101
|
+
font-size: 1rem;
|
|
102
|
+
border: 1px solid #ccc;
|
|
103
|
+
border-radius: 4px;
|
|
104
|
+
width: 100%;
|
|
105
|
+
max-width: 300px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
<%
|
|
67
109
|
}
|
|
68
110
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
111
|
+
%><%if(useVueRouter) {
|
|
112
|
+
%>.routerBtn {
|
|
113
|
+
margin-top: 1rem;
|
|
114
|
+
padding: 0.5rem 1rem;
|
|
115
|
+
font-size: 1rem;
|
|
116
|
+
border: none;
|
|
117
|
+
background: none;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.active-link {
|
|
121
|
+
font-weight: bold;
|
|
122
|
+
color: hsla(160, 100%, 30%, 1);
|
|
123
|
+
border-bottom: 2px solid hsla(160, 100%, 37%, 1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
<%
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
%>@media (min-width: 1024px) {
|
|
130
|
+
header {
|
|
131
|
+
display: flex;
|
|
132
|
+
place-items: center;
|
|
133
|
+
padding-right: calc(var(--section-gap) / 2);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.logo {
|
|
137
|
+
margin: 0 2rem 0 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
header .wrapper {
|
|
141
|
+
display: flex;
|
|
142
|
+
place-items: flex-start;
|
|
143
|
+
flex-wrap: wrap;
|
|
144
|
+
}
|
|
73
145
|
}
|
|
74
|
-
|
|
75
|
-
</style>
|
|
146
|
+
</style>
|