Created
February 17, 2021 21:49
-
-
Save WallasFaria/365a041a148d1663033ee8e87eced7a4 to your computer and use it in GitHub Desktop.
Exemplo vuejs
This file contains hidden or 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
var app = new Vue({ | |
el: '#app', | |
data: { | |
selecionado: { | |
endereco: {}, | |
preco: 0, | |
tempo: 0, | |
}, | |
ultimo: '', | |
enderecos: [ | |
{ id: 1, nome: 'Rua Rio Bonito 1', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 2, nome: 'Rua Rio Bonito 2', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 3, nome: 'Rua Rio Bonito 3', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 4, nome: 'Rua Rio Bonito 4', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 5, nome: 'Rua Rio Bonito 5', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 6, nome: 'Rua Rio Bonito 6', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 7, nome: 'Rua Rio Bonito 6', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 8, nome: 'Rua Rio Bonito 6', cep: '28015-190', bairro: 'Jockey' }, | |
{ id: 9, nome: 'Rua Lacerda Sobrinho', cep: '28015-190', bairro: 'Centro' }, | |
{ id: 10, nome: 'Rua Lacerda Sobrinho', cep: '28015-190', bairro: 'Centro' }, | |
{ id: 11, nome: 'Rua Lacerda Sobrinho', cep: '28015-190', bairro: 'Centro' }, | |
{ id: 12, nome: 'Rua Lacerda Sobrinho', cep: '28015-190', bairro: 'Centro' }, | |
{ id: 13, nome: 'Rua Lacerda Sobrinho', cep: '28015-190', bairro: 'Centro' }, | |
{ id: 14, nome: 'Rua Lacerda Sobrinho', cep: '28015-190', bairro: 'Centro' }, | |
], | |
selecionados: [ | |
{ | |
endereco: { id: 1, nome: 'Rua Rio Bonito 1', cep: '28015-190', bairro: 'Jockey' }, | |
preco: 7.00, | |
tempo: 30 | |
} | |
] | |
}, | |
methods: { | |
selecionar(endereco) { | |
this.selecionado = { | |
endereco: endereco, | |
preco: 0, | |
tempo: 0, | |
} | |
}, | |
adicionar() { | |
this.selecionados.push(this.selecionado) | |
}, | |
} | |
}) |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" | |
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> | |
<style> | |
.selected { | |
background-color: #f2f2f2; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="app"> | |
<div class="row"> | |
<div class="col"> | |
<div id="enderecos-disponiveis"> | |
<ul> | |
<li | |
v-for="endereco of enderecos" | |
:key="endereco.id" | |
@click="selecionar(endereco)" | |
:class="{ selected: endereco.id === selecionado.endereco.id }" | |
> | |
{{endereco.nome}} - {{endereco.cep}} | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div class="col"> | |
<div class="actions"> | |
<button class="btn btn-primary mb-2" @click="adicionar()">></button> | |
<button class="btn btn-primary"> | |
< | |
</button> | |
</div> | |
</div> | |
<div class="col"> | |
<div id="enderecos-selecionados"> | |
<ul> | |
<li v-for="item of selecionados" :key="item.endereco.id"> | |
{{item.endereco.nome}} - {{item.endereco.cep}} {{item.preco}} {{item.tempo}} | |
<input type="hidden" name="address[][id]" :value="item.endereco.id"> | |
<input type="hidden" name="address[][price]" :value="item.preco"> | |
<input type="hidden" name="address[][time]" :value="item.tempo"> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div class="col-12"> | |
{{ selecionado.endereco.nome }} | |
<label for="">Preço</label> | |
<div class="col-2"> | |
<div class="input-group"> | |
<div class="input-group-prepend"> | |
<span class="input-group-text">R$</span> | |
</div> | |
<input type="text" v-model="selecionado.preco" class="form-control money w-70"> | |
</div> | |
</div> | |
<label for="">Tempo de Entrega</label> | |
<input type="text" class="form-control" v-model="selecionado.tempo"> | |
</div> | |
</div> | |
<!-- Option 1: Bootstrap Bundle with Popper --> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | |
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" | |
crossorigin="anonymous"></script> | |
<!-- Option 2: Separate Popper and Bootstrap JS --> | |
<!-- | |
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script> | |
--> | |
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> | |
<script src="./app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment