Created
August 25, 2022 23:59
-
-
Save fabioebner/4deb004ee0357ad3ce50673ac9e58fbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
.... | |
</div> | |
</template> | |
<script setup> | |
const props = defineProps(["titulo", "itens"]); | |
const emit = defineEmits(["update:itens"]); | |
const categoria = ref(""); | |
const categorias = reactive([]); | |
const mensagem = ref(""); | |
function addCategoria() { | |
if (categoria.value) { | |
if (categorias.indexOf(categoria.value.toUpperCase()) < 0) { | |
categorias.push(categoria.value.toUpperCase()); | |
categoria.value = null; | |
mensagem.value = null; | |
emit("update:itens", categorias); | |
} else { | |
mensagem.value = "Categoria ja adicionada"; | |
} | |
} else { | |
mensagem.value = "Campo obrigatório"; | |
} | |
} | |
function removerCategoria(item) { | |
categorias.splice(categorias.indexOf(item), 1); | |
emit("update:itens", categorias); | |
mensagem.value = null; | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="flex justify-center h-screen"> | |
<FormItem | |
titulo="Categorias do evento" | |
v-model:itens="categorias" | |
></FormItem> | |
</div> | |
<button | |
type="button" | |
@click="atualizar" | |
class="ml-2 text-white h-10 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" | |
> | |
Salvar | |
</button> | |
</template> | |
<script setup> | |
const nome = ref(""); | |
const categorias = reactive([]); | |
function atualizar() { | |
console.log("atualizou"); | |
console.log(categorias); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment