Skip to content

Commit 9ce0744

Browse files
committed
init
1 parent bf67a88 commit 9ce0744

6 files changed

Lines changed: 218 additions & 60 deletions

File tree

doc/.vitepress/config/en.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export const en = defineConfig({
6060
text: 'VitePluginMettle',
6161
link: '/tool/vitePluginMettle/',
6262
},
63+
{
64+
text: 'MettleJsxRuntime',
65+
link: '/tool/mettleJsxRuntime/',
66+
},
6367
{
6468
text: 'BabelPluginMettleHtml',
6569
link: '/tool/babelPluginMettleHtml/',
@@ -68,10 +72,6 @@ export const en = defineConfig({
6872
text: 'BabelPresetMettle',
6973
link: '/tool/babelPresetMettle/',
7074
},
71-
{
72-
text: 'MettleJsxRuntime',
73-
link: '/tool/mettleJsxRuntime/',
74-
},
7575
],
7676
},
7777
{
@@ -91,8 +91,8 @@ export const en = defineConfig({
9191
link: '/other/ide/',
9292
},
9393
{
94-
text: 'Browser Compatibility',
95-
link: '/other/browser/',
94+
text: 'Adapt',
95+
link: '/other/adapt/',
9696
},
9797
{
9898
text: 'About',

doc/.vitepress/config/zh.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export const zh = defineConfig({
5454
text: 'VitePluginMettle',
5555
link: '/zh/tool/vitePluginMettle/',
5656
},
57+
{
58+
text: 'MettleJsxRuntime',
59+
link: '/zh/tool/mettleJsxRuntime/',
60+
},
5761
{
5862
text: 'BabelPluginMettleHtml',
5963
link: '/zh/tool/babelPluginMettleHtml/',
@@ -62,10 +66,6 @@ export const zh = defineConfig({
6266
text: 'BabelPresetMettle',
6367
link: '/zh/tool/babelPresetMettle/',
6468
},
65-
{
66-
text: 'MettleJsxRuntime',
67-
link: '/zh/tool/mettleJsxRuntime/',
68-
},
6969
],
7070
},
7171
{
@@ -85,8 +85,8 @@ export const zh = defineConfig({
8585
link: '/zh/other/ide/',
8686
},
8787
{
88-
text: '浏览器兼容性',
89-
link: '/zh/other/browser/',
88+
text: '适配',
89+
link: '/zh/other/adapt/',
9090
},
9191
{
9292
text: '关于',

doc/en/other/adapt/index.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Adapt
2+
3+
If you want to use Mettle in an application project developed with another front-end framework, that's fine too. Mettle is very flexible and can be easily adapted.
4+
5+
## Vue
6+
7+
**main.js**
8+
9+
```js
10+
import { createApp } from 'vue';
11+
import { createPinia } from 'pinia';
12+
import App from './App.vue';
13+
import mettle from './mettle-plugin';
14+
15+
const pinia = createPinia();
16+
const app = createApp(App);
17+
18+
app.use(pinia);
19+
app.mount('#app');
20+
21+
app.use(mettle);
22+
```
23+
24+
**App.vue**
25+
26+
```vue
27+
<script setup>
28+
import { ref,h } from 'vue'
29+
import { useCounterStore } from './store';
30+
31+
const counterStore = useCounterStore()
32+
const add = ()=>{
33+
counterStore.increment()
34+
}
35+
</script>
36+
37+
<template>
38+
<div>
39+
<button @click="add">add</button>
40+
<div id="mettle-inner"></div>
41+
</div>
42+
</template>
43+
44+
```
45+
46+
**mettle-plugin.jsx**
47+
48+
```jsx
49+
import { createApp } from 'mettle';
50+
import App from '@/mettle/App.jsx';
51+
52+
export default {
53+
install: () => {
54+
createApp(<App />, '#mettle-inner');
55+
},
56+
};
57+
```
58+
59+
**mettle/App.jsx**
60+
61+
```jsx
62+
import { watch } from 'vue';
63+
import { useCounterStore } from '@/store';
64+
65+
function App({ setData }) {
66+
const counterStore = useCounterStore();
67+
68+
watch(
69+
() => counterStore.count,
70+
(newVal) => {
71+
console.log(newVal);
72+
setData();
73+
}
74+
);
75+
76+
return () => (
77+
<fragment>
78+
<h1>{counterStore.count}</h1>
79+
<h2>{counterStore.doubleCount}</h2>
80+
</fragment>
81+
);
82+
}
83+
84+
export default App;
85+
```
86+
87+
**store/index.js**
88+
89+
```js
90+
import { defineStore } from 'pinia';
91+
import { ref, computed } from 'vue';
92+
93+
export const useCounterStore = defineStore('counter', () => {
94+
const count = ref(0);
95+
const name = ref('Eduardo');
96+
const doubleCount = computed(() => count.value * 2);
97+
function increment() {
98+
count.value++;
99+
}
100+
101+
return { count, name, doubleCount, increment };
102+
});
103+
```

doc/en/other/browser/index.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

doc/zh/other/adapt/index.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# 适配
2+
3+
如果你想在其他前端框架开发的应用项目中使用 Mettle,也是没有问题的。Mettle 非常灵活,可以轻松适配。
4+
5+
## Vue
6+
7+
**main.js**
8+
9+
```js
10+
import { createApp } from 'vue';
11+
import { createPinia } from 'pinia';
12+
import App from './App.vue';
13+
import mettle from './mettle-plugin';
14+
15+
const pinia = createPinia();
16+
const app = createApp(App);
17+
18+
app.use(pinia);
19+
app.mount('#app');
20+
21+
app.use(mettle);
22+
```
23+
24+
**App.vue**
25+
26+
```vue
27+
<script setup>
28+
import { ref,h } from 'vue'
29+
import { useCounterStore } from './store';
30+
31+
const counterStore = useCounterStore()
32+
const add = ()=>{
33+
counterStore.increment()
34+
}
35+
</script>
36+
37+
<template>
38+
<div>
39+
<button @click="add">add</button>
40+
<div id="mettle-inner"></div>
41+
</div>
42+
</template>
43+
44+
```
45+
46+
**mettle-plugin.jsx**
47+
48+
```jsx
49+
import { createApp } from 'mettle';
50+
import App from '@/mettle/App.jsx';
51+
52+
export default {
53+
install: () => {
54+
createApp(<App />, '#mettle-inner');
55+
},
56+
};
57+
```
58+
59+
**mettle/App.jsx**
60+
61+
```jsx
62+
import { watch } from 'vue';
63+
import { useCounterStore } from '@/store';
64+
65+
function App({ setData }) {
66+
const counterStore = useCounterStore();
67+
68+
watch(
69+
() => counterStore.count,
70+
(newVal) => {
71+
console.log(newVal);
72+
setData();
73+
}
74+
);
75+
76+
return () => (
77+
<fragment>
78+
<h1>{counterStore.count}</h1>
79+
<h2>{counterStore.doubleCount}</h2>
80+
</fragment>
81+
);
82+
}
83+
84+
export default App;
85+
```
86+
87+
**store/index.js**
88+
89+
```js
90+
import { defineStore } from 'pinia';
91+
import { ref, computed } from 'vue';
92+
93+
export const useCounterStore = defineStore('counter', () => {
94+
const count = ref(0);
95+
const name = ref('Eduardo');
96+
const doubleCount = computed(() => count.value * 2);
97+
function increment() {
98+
count.value++;
99+
}
100+
101+
return { count, name, doubleCount, increment };
102+
});
103+
```

doc/zh/other/browser/index.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)