3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vueに早く出会いたかった

Last updated at Posted at 2024-05-31

なぜ Vue?

エンジニアは少ないコードでシンプルに書きたいと常日頃から思っていると思います。Vue.jsはReactなどを学習してきたからこそ書き方の違いをこの記事で書きたいと思います。

繰り返し処理

list.jsx
    const items = [];

    return(
    	{items.map(item) => (
    		<div>
    			{ item }
    		</div>
    	)}  
    )
list.vue
<script>
	const items = [];
</script>

<template>
	<div v-for="item in items">
		{{ item }}
	</div>
</tempalte>

入力処理

input.jsx
import { useState } from 'react';

const [value, setValue] = useState("");

returun(
	<>
		<input
			type="text"
			onChange={(e) => setValue(e.target.value)}
			value={ value }
		/>
	</>
)
input.vue
<script setup>
import { ref } from 'vue';
const value = ref('');
</script>

<template>
	<input
		type="text"
		v-model="value"
		:value={{ value }}
	/>
</template>

コンポーネント

componet.vue
<script setup>
import { ref } from 'vue'
import A from './componentA';
import B from './componentB';
import C from './componentC';

const currentComponent = ref(A)
</script>

<template>
	<button @click="currentComponent = A">A</button>
	<button @click="currentComponent = B">B</button>
	<button @click="currentComponent = C">C</button>
	<component :is="currentComponent"/>
</template>

これを知ってからjsx/tsxの書き方には戻れないと思いました。

3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?