• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Day 2 - Create the ShoppingCart component

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
On day 2, I will delete the boilerplate codes and create the ShoppingCart component.

Create the shopping cart component

  • Vue 3 application

Deleted all the files from the components/ folder.
Create ShoppingCart.vue in the component/ folder.


<script setup lang="ts">
</script>

<template>
<p>Shopping Cart</p>
</template>

<style scoped>
</style>

The template has a paragraph element that displays "Shopping Cart".

Updated the codes in App.vue that failed to compile


// App.vue
<script setup lang="ts">
import ShoppingCart from './components/ShoppingCart.vue'
</script>

<template>
<ShoppingCart />
</template>
  • SvelteKit application

Create shopping-cart.svelte in the lib/ folder.


// shopping-cart.svelte

<script lang="ts">
</script>


<p>Shopping Cart</p>

The template has a paragraph element that displays “Shopping Cart”.


// index.ts
export * from './shopping-cart.svelte';

Export shopping-cart.svelte from index.ts.

Updated the codes in +page.svelte to include the ShoppingCart component


// +page.svelte
<script lang="ts">
import ShoppingCart from '$lib/shopping-cart.svelte';
</script>

<ShoppingCart />
  • Angular 19 application

Use Angular CLI to generate the ShoppingCartComponent. The schematic will create shopping-cart.component.html, shopping-cart.component.ts, shopping-cart.component.scss and shopping-cart.component.spect.ts


ng g c shopping-cart/shoppingCart --flat

I will use an inline template for the component. Let's delete shopping-cart.component.html, shopping-cart.component.scss, and shopping-cart.component.spect.ts.


import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-shopping-cart',
imports: [],
template: `
<p>Shopping Cart</p>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ShoppingCartComponent {}

The inline template has a paragraph element that displays "Shopping Cart".

Added the ShoppingCartComponent to the imports array of AppComponent.


// app.component.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ShoppingCartComponent } from './shopping-cart/shopping-cart.component';

@Component({
selector: 'app-root',
imports: [ShoppingCartComponent],
template: '<app-shopping-cart />',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {}

We have successfully created the shopping cart component and displayed it in the application.

Resources



Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу