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
<!-- CustomInput.vue --> | |
<template> | |
... | |
<p v-if="error">{{ error }}</p> | |
... | |
</template> | |
<script> | |
... | |
data() { |
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
<!-- CustomInput.vue --> | |
<template> | |
... | |
<input type="text" :name="name" :value="value" @input="onInput" /> | |
... | |
</template> | |
<script> | |
... | |
methods: { |
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
<!-- CustomInput.vue --> | |
<template> | |
<label> | |
{{ label }} | |
<input type="text" :name="name" :value="value" @input="$emit('input', $event.target.value)" /> | |
</label> | |
</template> | |
<script> | |
export default { |
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
<!-- App.vue --> | |
<template> | |
<custom-input :label="label" :value="model" /> | |
</template> | |
... |
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
<!-- CustomInput.vue --> | |
<template> | |
<label> | |
{{ label }} | |
<input type="text" :name="name" v-model="value" /> | |
</label> | |
</template> | |
<script> | |
export default { |
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
<!-- App.vue --> | |
<template> | |
<custom-input :label="label" v-model="model" /> | |
</template> | |
<script> | |
import CustomInput from './components/CustomInput.ue'; | |
export default { | |
name: 'App', |
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> | |
<label> | |
Username | |
<input type="text" name="username" v-model="username"> | |
</label> | |
</template> | |
<script> | |
export default { | |
name: 'UsernameInput', |
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
fetch(URL_TO_POST, { | |
method: 'post', | |
body: new FormData(document.querySelector('#my-form')) | |
}) | |
.then(function(response) { | |
// trate a resposta aqui | |
}); |
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
// Podemos instanciar um Header já passando um objeto | |
// com as propriedades que queremos setar | |
let headers = new Headers({ | |
'Content-Type': 'text/plain', | |
'X-Custom-Header': 'valor' | |
}); | |
// mas também podemos adicionar programaticamente | |
// depois de já termos instanciado | |
headers.append('X-Custom-Header', 'valor'); |
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
fetch(URL_TO_FETCH, { | |
method: 'POST', | |
mode: 'cors', // pode ser cors ou basic(default) | |
redirect: 'follow', | |
headers: new Headers({ | |
'Content-Type': 'text/plain' | |
}) | |
}) | |
.then(function(response) { | |
// tratar a response |