RosettaJS: Comparativas de Vue, React y Angular

View Logic

Inline Styles with Objects

Inline styles can be defined as an object of CSS properties and applied directly to an element.

Example

Applying an inline style object to an avatar.

Vue:style

<script setup lang="ts">
const avatarStyles = {
  width: '64px',
  height: '64px',
}
</script>

<template>
  <img
    src="avatar.jpg"
    alt="Profile avatar"
    :style="avatarStyles"
  />
</template>

It uses the :style binding to bind a style object to the avatar.

Reactstyle

function ProfileAvatar() {
  const avatarStyles = {
    width: '64px',
    height: '64px',
  }

  return (
    <img
      src="avatar.jpg"
      alt="Profile avatar"
      style={avatarStyles}
    />
  )
}

It passes a style object to the avatar style prop.

Angular[style]

import { Component } from '@angular/core'

@Component({
  selector: 'app-profile-avatar',
  standalone: true,
  template: `
    <img
      src="avatar.jpg"
      alt="Profile avatar"
      [style]="avatarStyles"
    />
  `,
})
export class ProfileAvatarComponent {
  avatarStyles = {
    width: '64px',
    height: '64px',
  }
}

It uses the [style] binding to bind a style object to the avatar.