Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit e8007a5

Browse files
committed
wip(framework/vue): it can work.
1 parent 0fa2bc2 commit e8007a5

File tree

12 files changed

+139
-17
lines changed

12 files changed

+139
-17
lines changed

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ You will need [Deno](https://deno.land/) 1.20+.
1919
6. Make a [pull request](https://github.com/alephjs/aleph.js/pulls).
2020
7. Merge to master branch by our maintainers.
2121

22+
### react-app
23+
2224
```bash
2325
# run the example app in development mode
2426
deno task dev examples/react-app
@@ -30,6 +32,19 @@ deno task start examples/react-app
3032
deno task build examples/react-app
3133
```
3234

35+
### vue-app
36+
37+
```bash
38+
# run the example app in development mode
39+
deno task dev examples/vue-app
40+
41+
# run the example app in production mode
42+
deno task start examples/vue-app
43+
44+
# build the example app into a worker for serverless platform
45+
deno task build examples/vue-app
46+
```
47+
3348
## Testing
3449

3550
You can run all tests with the following command:

examples/vue-app/app.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
import { ref } from "vue"
33
44
const msg = ref("Hello world!")
5+
6+
function click() {
7+
location.pathname = '/hello'
8+
}
59
</script>
610

711
<template>
812
<h1 v-if="msg">{{ msg }}</h1>
913
<h1 v-if="!msg" style="color: #ccc;">Please type something</h1>
1014
<input v-model="msg" placeholder="Please type something">
15+
<button @click="click">hello page</button>
1116
</template>
1217

1318
<style scoped>

examples/vue-app/hello.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup>
2+
import { ref } from "vue"
3+
4+
const msg = ref("hello page")
5+
6+
function click() {
7+
location.pathname = ''
8+
}
9+
</script>
10+
11+
<template>
12+
<div>{{ msg }}</div>
13+
<button @click="click">home page</button>
14+
</template>

examples/vue-app/index.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<link rel="icon" href="./assets/logo.svg">
8-
<style>
9-
body {
10-
margin: 0;
11-
width: 100vw;
12-
height: 100vh;
13-
display: flex;
14-
align-items: center;
15-
justify-content: center;
16-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
17-
}
18-
</style>
8+
<link rel="stylesheet" href="./style/app.css">
199
</head>
2010

2111
<body>

examples/vue-app/main.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
import { createApp } from "vue";
2-
import app from "./app.vue";
2+
import { createRouter, createWebHistory } from "vue-router";
3+
import App from "./app.vue";
4+
import Hello from "./hello.vue";
5+
import { routes } from "./routes.js";
36

4-
createApp(app).mount("#root", true);
7+
const router = createRouter({
8+
history: createWebHistory(),
9+
routes,
10+
});
11+
12+
const pathname = location.pathname;
13+
const app = createApp(
14+
{
15+
"/": App,
16+
"/hello": Hello,
17+
}[pathname],
18+
);
19+
20+
app.use(router);
21+
await router.push({ path: pathname });
22+
23+
router.isReady().then(() => {
24+
app.mount("#root", true);
25+
});

examples/vue-app/routes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import app from "./app.vue";
2+
import hello from "./hello.vue";
3+
4+
const routes = [
5+
{
6+
path: "/",
7+
component: app,
8+
},
9+
{ path: "/hello", component: hello },
10+
];
11+
12+
export { routes };

examples/vue-app/server.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1-
import { serve } from "aleph/server";
21
import { createSSRApp } from "vue";
2+
import { createMemoryHistory, createRouter } from "vue-router";
3+
import { serve } from "aleph/server";
34
import { renderToString } from "vue/server-renderer";
4-
import app from "./app.vue";
5+
import App from "./app.vue";
6+
import Hello from "./hello.vue";
7+
import { routes } from "./routes.js";
8+
9+
const createSSRApp_ = async (ctx) => {
10+
const pathname = ctx.url.pathname;
11+
const ssrApp = createSSRApp(
12+
{
13+
"/": App,
14+
"/hello": Hello,
15+
}[pathname],
16+
);
17+
const router = createRouter({
18+
history: createMemoryHistory(),
19+
routes,
20+
});
21+
ssrApp.use(router);
22+
23+
await router.push({ path: pathname });
24+
await router.isReady();
25+
26+
return ssrApp;
27+
};
528

629
serve({
7-
ssr: async (_ctx) => await renderToString(createSSRApp(app)),
30+
config: {
31+
routes: "./routes/**/*.{vue,tsx,ts}",
32+
unocss: {
33+
// to enable unocss, please add presets:
34+
// presets: [ unoPreset ],
35+
},
36+
},
37+
ssr: async (ctx) => await renderToString(await createSSRApp_(ctx)),
838
});

examples/vue-app/style/app.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import url('./reset.css');
2+
3+
body {
4+
width: 100vw;
5+
height: 100vh;
6+
display: flex;
7+
align-items: center;
8+
justify-content: center;
9+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
10+
}

examples/vue-app/style/reset.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
margin: 0;
3+
}

framework/vue/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// todo: add vue framework support
1+
export { createSSRApp } from "./router.ts";

0 commit comments

Comments
 (0)