Daftar Isi:
1
Politeknik Elektronika Negeri Surabaya
2
Politeknik Elektronika Negeri Surabaya
3
Politeknik Elektronika Negeri Surabaya
const routes = [
{
path: "",
name: "",
component: ,
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;
4
Politeknik Elektronika Negeri Surabaya
createApp(App).use(router).mount('#app')
5
Politeknik Elektronika Negeri Surabaya
Untuk About.vue
<template>
Ini Halaman About
</template>
sintak berikut:
import { createWebHistory, createRouter } from "vue-router";
import Home from '../components/Home.vue'
import About from '../components/About.vue'
const routes = [
{
path: "/",
name: "home",
component: Home,
},
{
path: "/about",
name: "about",
component: About,
},
];
const router = createRouter({
history: createWebHistory(),
6
Politeknik Elektronika Negeri Surabaya
routes,
});
export default router;
7
Politeknik Elektronika Negeri Surabaya
component: Home,
},
8
Politeknik Elektronika Negeri Surabaya
9
Politeknik Elektronika Negeri Surabaya
>About</router-link
>
</li>
</ul>
</div>
</nav>
<router-view></router-view>
</template>
createApp(AppNav).use(router).mount('#app')
10
Politeknik Elektronika Negeri Surabaya
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfID
Pvg6uqKI2xXr2" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
integrity="sha384-
B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVI
U" crossorigin="anonymous">
<title>Vite + Vue</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
11
Politeknik Elektronika Negeri Surabaya
- Untuk About
12
Politeknik Elektronika Negeri Surabaya
];
const router = createRouter({
history: createWebHistory(),
routes,
linkActiveClass: "active",
});
export default router;
13
Politeknik Elektronika Negeri Surabaya
14
Politeknik Elektronika Negeri Surabaya
15
Politeknik Elektronika Negeri Surabaya
min-height: 90vh;
}
</style>
16
Politeknik Elektronika Negeri Surabaya
};
},
},
};
</script>
17
Politeknik Elektronika Negeri Surabaya
user: {
name: "",
email: "",
password: "",
password_confirm: "",
},
errors: {},
};
},
methods: {
handleSubmit() {
this.errors = {
email: ["The email field is required"],
password: ["The password field is required"],
};
},
},
};
</script>
18
Politeknik Elektronika Negeri Surabaya
<script>
export default {
inheritAttrs: false,
props: {
label: {
type: String,
required: true,
},
modelValue: {
type: [String, Number],
default: null,
},
modelModifiers: {
default: () => ({}),
},
error: {
type: [Array, String],
default: null,
},
},
methods: {
handleInput(event) {
let value = event.target.value;
if (this.modelModifiers.number) {
19
Politeknik Elektronika Negeri Surabaya
value = Number(value);
}
if (this.modelModifiers.trim) {
value = value.trim();
}
this.$emit("update:modelValue", value);
},
},
computed: {
labelFor() {
return this.$attrs.id ? { for: this.$attrs.id } : {};
},
getError() {
return Array.isArray(this.error) ? this.error.join(", ") : this.error;
},
},
};
</script>
// createApp(AppNav).use(router).mount('#app')
const app = createApp(AppNav);
app.use(router);
app.component("base-input", BaseInput);
app.mount('#app');
20
Politeknik Elektronika Negeri Surabaya
<template>
<nav
class="navbar navbar-light bg-white navbar-expand-lg bg-light border-bottom"
>
<div class="container">
<a class="navbar-brand" href="#"> VueCommerce </a>
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<router-link class="nav-link" to="/">Home</router-link>
</li>
<li class="nav-item">
<router-link class="nav-link" :to="{ name: 'about' }"
>About</router-link
>
</li>
</ul>
</div>
</nav>
<router-view></router-view>
</template>
21
Politeknik Elektronika Negeri Surabaya
22
Politeknik Elektronika Negeri Surabaya
component: RegisterForm,
name: "auth.register",
},
],
},
];
23
Politeknik Elektronika Negeri Surabaya
24
Politeknik Elektronika Negeri Surabaya
25
Politeknik Elektronika Negeri Surabaya
26
Politeknik Elektronika Negeri Surabaya
27
Politeknik Elektronika Negeri Surabaya
28
Politeknik Elektronika Negeri Surabaya
"categoryId": 12,
"price": 115
},
{
"id": 4,
"name": "Gorgeous Concrete Pizza",
"category": "Garden",
"categoryId": 7,
"price": 250
},
{
"id": 5,
"name": "Refined Plastic Shoes",
"category": "Health",
"categoryId": 9,
"price": 844
},
{
"id": 6,
"name": "Awesome Metal Soap",
"categoryId": 17,
"category": "Tools",
"price": 326
},
{
"id": 7,
"name": "Intelligent Fresh Mouse",
"category": "Home",
"categoryId": 10,
"price": 783
},
{
"id": 8,
"name": "Licensed Soft Keyboard",
"category": "Music",
"categoryId": 15,
"price": 361
},
{
"id": 9,
"name": "Fantastic Rubber Pants",
"category": "Garden",
"categoryId": 7,
"price": 786
29
Politeknik Elektronika Negeri Surabaya
},
{
"id": 10,
"name": "Awesome Rubber Ball",
"category": "Automotive",
"categoryId": 1,
"price": 696
}
]
}
30
Politeknik Elektronika Negeri Surabaya
<div>
<table border="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Action</th>
</tr>
<tr v-for="(product, index) in products">
<td>{{ index + 1 }}</td>
<td>{{ product.name }}</td>
<td>{{ product.category }}</td>
<td>{{ product.price }}</td>
<td><router-link
class="btn btn-sm btn-info"
:to="{ name: 'products.edit', params: { id: product.id } }"
>Edit</router-link
></td>
</tr>
</table>
</div>
</template>
<script>
/* Ambil data json dengan axios*/
import axios from "axios";
export default {
data() {
return {
form: {
id: "",
name: "",
},
products: [],
updateSubmit: false,
};
},
mounted() {
this.load();
},
methods: {
load() {
axios
.get("http://localhost:3000/products")
31
Politeknik Elektronika Negeri Surabaya
.then((res) => {
this.products = res.data; //respon dari rest api dimasukan ke products
})
.catch((err) => {
console.log(err);
});
},
},
};
</script>
const routes = [
{
path: "/home",
name: "home",
component: Home,
},
{
path: "/about",
name: "about",
component: About,
},
32
Politeknik Elektronika Negeri Surabaya
{
path: "/products",
component: ProductsView,
children: [
{
path: "",
component: ProductList,
name: "products",
},
{
path: ":id/edit",
name: "products.edit",
component:ProductForm,
props: true,
},
],
},
{
path: "/auth",
component: AuthView,
children: [
{
path: "login",
component: LoginForm,
name: "auth.login",
},
{
path: "register",
component: RegisterForm,
name: "auth.register",
},
],
},
];
const router = createRouter({
history: createWebHistory(),
routes,
linkActiveClass: "active",
});
export default router;
33
Politeknik Elektronika Negeri Surabaya
34
Politeknik Elektronika Negeri Surabaya
35
Politeknik Elektronika Negeri Surabaya
11. Lalu untuk coba rute dinamis kita coba cek link
di tombol edit dengan cara klik kanan pointer mouse
lalu klik “inspect element” atau “inspect”.
36
Politeknik Elektronika Negeri Surabaya
37
Politeknik Elektronika Negeri Surabaya
- SELESAI -
38
Politeknik Elektronika Negeri Surabaya
Tugas Praktikum
aplikasi sejenis).
https://pens.id/tugasMKPermogramanWeb2023.
39
Politeknik Elektronika Negeri Surabaya
40