Skip to content

Commit 83f9ab6

Browse files
committed
Hover Button
1 parent 0809319 commit 83f9ab6

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

src/App.vue

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<script setup>
22
import { RouterView } from 'vue-router'
33
import RouterButton from "@/components/RouterButton.vue";
4+
import { introExamples} from "@/examplelists.js";
45
56
</script>
67

78
<template>
89
<div class="flex flex-row gap-x-2 h-full w-full">
9-
<div class="flex flex-col w-36 p-2">
10-
<div class="flex flex-col">
11-
<h2>Introduction</h2>
12-
<RouterButton to-path="/helloworld" name="Hello World"/>
13-
<RouterButton to-path="/dynamicattributes" name="Dynamic Attributes"/>
14-
<RouterButton to-path="/styling" name="Styling"/>
15-
<RouterButton to-path="/nestedcomponents" name="Nested Component"/>
16-
<RouterButton to-path="/htmldirective" name="HTML Directive"/>
10+
<div class="flex flex-col w-56 p-2">
11+
<p class="text-2xl">Vue 3 Examples</p>
12+
<br>
13+
<div class="flex flex-col gap-y-2">
14+
<p class="text-xl">Introduction</p>
15+
<RouterButton
16+
v-for="example in introExamples"
17+
:key="example.name"
18+
:to-path="example.path"
19+
:name="example.name"
20+
/>
1721
</div>
1822

1923
</div>

src/components/ReplWrapper.vue

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ store.setFiles({
2525
})
2626
2727
28-
2928
</script>
3029

3130
<template>

src/components/RouterButton.vue

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<script setup>
2+
import { defineProps, computed } from 'vue';
3+
import { useRoute } from 'vue-router';
4+
25
const props = defineProps({
36
toPath: {
47
type: String,
@@ -8,20 +11,29 @@ const props = defineProps({
811
type: String,
912
default: '/'
1013
}
11-
})
14+
});
1215
16+
const route = useRoute();
17+
const isSelected = computed(() => route.path === props.toPath);
1318
</script>
1419

1520
<template>
1621
<button
17-
class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-2 border border-gray-400 rounded shadow"
22+
:class="{'selected': isSelected, 'bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-2 border border-gray-400 rounded shadow': true}"
1823
@click="$router.push(props.toPath)"
1924
>
2025
{{ props.name }}
2126
</button>
22-
2327
</template>
2428

2529
<style scoped>
30+
.selected {
31+
background-color: #0056b3;
32+
color: white;
33+
}
34+
35+
button.selected:hover {
36+
background-color: #0056b3;
37+
}
2638
2739
</style>

src/examplelists.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
export const introExamples = [
3+
{
4+
name: "Hello World",
5+
path: "/helloworld"
6+
},
7+
{
8+
name: "Dynamic Attributes",
9+
path: '/dynamicattributes',
10+
},
11+
{
12+
name: "Styling",
13+
path: '/styling'
14+
},
15+
{
16+
name: "Nested Component",
17+
path: '/nestedcomponents'
18+
},
19+
{
20+
name: "HTML Directive",
21+
path: '/htmldirective'
22+
}
23+
]

src/views/htmldirective/default.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export const AppVue = `
22
<!-- Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to XSS attacks. Only use v-html on trusted content and never on user-provided content. -->
3-
<script setup>
4-
const htmlString = \`hello <b>world</b>\`;
5-
</script>
6-
73
<template>
84
<p v-html="htmlString"></p>
95
</template>
6+
7+
<script setup>
8+
const htmlString = \`hello <b>world</b>\`;
9+
</script>
1010
`.trimStart()

0 commit comments

Comments
 (0)