I have a project to add an ingredient in a recipe to "Shopping List".
And in this picture there are several ingredients at the bottom "sugar".
When I click on the plus sign I want to add the ingredient to the "shopping List".
How can I solve this problem?
In this file, you create an ingredient with this ingredient's data such as its name and quantity.
CreateIngredient:
<template>
<v-app>
<v-container>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<h2 class="btn-style">Add Ingredient</h2>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<form #submit.prevent="onAddIngredient">
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field name="id" label="Id" id="id" v-model="id" color="#43A047" required>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field name="name" label="Name" id="name" v-model="Name" color="#43A047" required>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field name="ingredientsQuantity" label="Ingredients Quantity" id="ingredientsQuantity" v-model="Quantity" color="#43A047" multi-line required>
</v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<v-btn class="green darken-1 color" type="submit">
Add
</v-btn>
</v-flex>
</v-layout>
</form>
</v-flex>
</v-layout>
</v-container>
</v-app>
</template>
<script>
export default {
data() {
return {
id: "",
Name: "",
Quantity: "",
};
},
computed: {
formIsValid() {
return (
this.id !== "" &&
this.Name !== "" &&
this.Quantity !== ""
);
}
},
methods: {
onAddIngredient() {
if (!this.formIsValid) {
return;
}
const ingredientData = {
id: this.id,
Name: this.Name,
Quantity: this.Quantity
};
this.$store.commit("createIngredients", ingredientData);
const stringifiedData = JSON.stringify(ingredientData);
// console.log("S: ", stringifiedData);
localStorage.setItem("ingredient", stringifiedData);
console.log("We got : ", JSON.parse(localStorage.getItem("ingredient")));
}
},
};
</script>
<style scoped>
.btn-style {
color: #43a047;
}
.color {
color: #fafafa;
}
</style>
And this file that displays all the ingredients
shoppingList:
<template>
<div>
<v-container class="mb-30">
<v-flex class="floating-right">
<v-btn large router to="/CreateNewIngrediets" class="green darken-1 btn-style margine mr-50">
<v-icon class="green darken-1 btn-style">mdi-plus</v-icon>
</v-btn>
</v-flex>
<v-container>
<v-layout row wrap v-for="ingredient in ingredients" :key="ingredient.id" class="mb-3 mt-4">
<v-flex xs6 sm8 md4 offset-sm1 offset-md2>
<v-card class="grey lighten-4 pl-3 ">
<v-container fluid>
<v-layout row class="pl-14">
<v-flex xs7 sm8 md9>
<v-card-title primary-title>
<v-flex xs7 sm8 md9>
<div>
{{ ingredient.Name }}
</div>
</v-flex>
<v-flex xs7 sm8 md9>
<div>
{{ ingredient.Quantity }}
</div>
</v-flex>
<v-flex xs5 sm4 md2>
<v-btn class="deleteColorIcon">
<v-icon left class=" pl-4" #click="
$store.commit('delete_ingredient', ingredient.id)
">
mdi-delete
</v-icon>
<!-- </v-btn> -->
</v-btn>
</v-flex>
</v-card-title>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-container>
</div>
</template>
<script>
export default {
computed: {
Recipes() {
return this.$store.getters.loadedRecipes;
},
ingredients() {
return this.$store.getters.loadedingredients;
}
}
};
</script>
<style scoped>
.color {
color: #43a047;
}
.deleteColorIcon {
color: #e53935;
}
.btn-style {
color: aliceblue;
}
</style>
And this file that displays the recipe as the image above, and through it, all the recipe elements, including the ingredients, are displayed.
Recipe:
<template>
<v-container>
<v-layout row wrap>
<v-flex x12>
<v-card>
<!-- <v-card-title> -->
<v-card-text>
<h4 class="btn-style mt-4 mb-4 font">
{{ recipe.title }}
</h4>
<v-img height="530px" :src="recipe.imageUrl" class="mb-4"></v-img>
<div class="btn-style mb-6">
{{ recipe.description }}
</div>
<div v-for="ing in recipe.ingredients" :key="ing.id">
{{ ing.Name }} {{ ing.Quantity }}
<v-btn class="green darken-1 color mb-5 ml-4 mr-4 pl-50">
<v-icon class="green darken-1 btn-style">mdi-plus</v-icon>
</v-btn>
</div>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<!-- <v-flex xs5 sm4 md2> -->
<v-btn class=" mb-4 mr-4">
<v-icon left class=" pl-4 ">
mdi-pen
</v-icon>
<!-- </v-btn> -->
</v-btn>
<!-- </v-flex> -->
</v-card-actions>
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import {
mapGetters
}
from "vuex";
export default {
props: ["id"],
computed: {
recipe() {
const loadedRecipe = this.$store.getters.loadedRecipe(this.id);
console.log("We loaded a recipe with value : ", loadedRecipe);
return loadedRecipe;
},
ingredient() {
return this.$store.getters.loadedingredient(this.id);
}
},
methods: {
}
};
</script>
<style scoped>
.btn-style {
color: #43a047;
}
.color {
color: #fafafa;
}
.deleteColorIcon {
color: #e53935;
}
.font {
font-size: 30px;
}
</style>
You can put a on click observer un your button, define a function that would execute in such case and pass it the object you want to store like so:
<div v-for="ing in recipe.ingredients" :key="ing.id">
{{ ing.Name }} {{ ing.Quantity }}
<v-btn class="green darken-1 color mb-5 ml-4 mr-4 pl-50" #click="addToShoppingList(ing)">
<v-icon class="green darken-1 btn-style">mdi-plus</v-icon>
</v-btn>
</div>
Then in vuex, store it in the state using an action and a mutator:
export default new Vuex.Store({
state: {
shoppingList: []
},
getters: {
getShoppingList(state) { return state.shoppingList }
},
mutations: {
ADD_ITEM_TO_SHOPPING_LIST(state, ingParam) {
state.shoppingList.push(ingParam);
}
}
,
actions: {
addItemToShoppingList({commit}, ingParam) {
commit('ADD_ITEM_TO_SHOPPING_LIST', ingParam);
}
}
And last thing in your methods like so:
export default {
methods: {
addToShoppingList(ingParam) {
this.$store.dispatch('addItemToShoppingList', ingParam);
}
}
}
Hope it helps ;)
Related
So I want to bind batch_code data from dashboard.vue parent to review.vue child component
so, the dashboard contains details like the batch_code, then I have trouble passing the data to the review component, of which it will get the batch_code upon clicking the "Rate and Review" button
when I did try, I am just getting null values from returning said data. any suggestions?
dashboard.vue
<template>
<div>
<v-col cols="10" class="mx-auto">
<v-card class="pa-4" outlined>
<v-card-title class="pb-0 pt-2">Dashbard</v-card-title>
<div v-if="checkifEmpty()">
<v-row>
<v-col
v-for="item in myBatch.all_batch"
:key="item.batch_code"
cols="6"
>
<v-card class="ma-2" outlined>
<div class="d-flex">
<v-avatar class="ma-3" size="150" tile>
<v-img :src="item.image"></v-img>
</v-avatar>
<div>
<v-card-title class="pb-0 pt-2"
>{{ item.offer }} ({{ item.level }})</v-card-title
>
<v-card-text>
<div class="mt-0">{{ item.techer_name }}</div>
<div class="mt-0">{{ item.batch_name }}</div>
<div class="Heading 6 pb-0">
{{ item.start_date }} -
{{ item.end_date }}
</div>
<div class="subtitle-1 pb-0">{{ item.type }}</div>
</v-card-text>
</div>
<v-btn elevation="3" v-on:click="openReviewDialog"
>Rate and Review!</v-btn
>
</div>
</v-card>
</v-col>
</v-row>
</div>
<div v-else>
<v-card-text class="pb-0 pt-2"
>You have no enrolled offers</v-card-text
>
</div>
</v-card>
</v-col>
<review />
</div>
</template>
<script>
import store from "../../store/index";
import review from "./review"
export default {
name: "Dashboard",
components:{
review,
},
computed: {
myBatch() {
return store.getters.getMyOffers;
},
},
methods: {
checkifEmpty() {
let batch = this.myBatch;
if (batch == null || batch.all_batch.length == 0) {
return false;
} else {
return true;
}
},
openReviewDialog() {
this.$store.dispatch("setreviewDialog");
this.sidebarFront = false;
}
},
};
</script>
<style>
</style>
review.vue
<template>
<v-row justify="center">
<v-dialog v-model="reviewDialog" persistent max-width="900px">
<v-card>
<v-card-title class="justify-center">
<span class="headline font-weight-bold"
>Rate and Review this Course!</span
>
</v-card-title>
<v-card-text>
<v-container fluid>
<v-row>
<v-col cols="12" sm="12" md="12">
<v-form
ref="userReview"
v-model="userReviewForm"
lazy-validation
>
<v-text-field
rounded
outlined
v-model="subject"
label="Subject"
required
></v-text-field>
<v-text-field
rounded
outlined
v-model="batch_code"
label="batch_code"
readonly
></v-text-field>
<v-textarea
rounded
outlined
v-model="review"
counter="250"
label="Review"
required
></v-textarea>
<v-rating v-model="rating">
<template v-slot:item="props">
<v-icon
:color="props.isFilled ? 'orange lighten-1' : 'grey lighten-1'"
size = "30"
#click="handleRatingChange(props)">mdi-star</v-icon>
</template>
</v-rating>
<div>
<v-btn
:loading="loginLoader"
large
block
rounded
elevation="0"
color="primary"
#click="submit"
>
Submit
</v-btn>
</div>
</v-form>
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<div class="close"> <v-btn color="error" text #click="closeReviewDialog()"> Close </v-btn></div>
</v-card-actions>
</v-card>
</v-dialog>
</v-row>
</template>
<script>
import store from "../../store/index";
export default {
props: {
item:{
batch_code: null;
}
},
name: "review",
data() {
return {
getters: store.getters,
rating: null
};
},
computed: {
reviewDialog: function () {
return this.getters.getreviewDialog;
},
},
methods: {
closeReviewDialog: function () {
//this.show = false;
//this.$refs.card.hide();
//store.dispatch("removeLoginError");
store.dispatch("setreviewDialog");
},
handleRatingChange(props){
console.log(props.index + 1)
this.rating = props.index +1
}
},
};
</script>
'''
p.s: i don't know if it's different when calling props for a component than to a dialog box.
just update your code like below tips,
openReviewDialog() {
this.$store.dispatch("setreviewDialog", **your_rating_data**);
this.sidebarFront = false;
}
so update your dispatch/action accordingly in store.
and when loading your form just pull data from the store using getter and show on dialog.
I have this Component to create a recipe, but I want to store the data in the local storage.
When I print the "recipeData" it is printed on the console.
For example, I enter the name of the recipe and the description for it, etc. and I print the data in the console and the elements I have entered are printed, but when I print "recipeData.title" it is printed that it is not defined.
And when I want to store the recipeData in the local storage, it does not store it.
How can i solve the problem?
<template>
<v-app>
<v-container>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<h2 class="btn-style">Create Recipe</h2>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<form #submit.prevent="onCreateRecipe">
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="title"
label="Title"
id="title"
v-model="title"
color="#43A047"
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="imageUrl"
label="ImageUrl"
id="imageUrl"
v-model="imageUrl"
color="#43A047"
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<img :src="imageUrl" height="300px" />
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="description"
label="Description"
id="description"
v-model="description"
color="#43A047"
multi-line
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="ingredients"
label="Ingredients"
id="ingredients"
v-model="ingredients"
color="#43A047"
multi-line
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<v-btn
class="green darken-1 color"
:disabled="!formIsValid"
type="submit"
>
Create Redcipe
</v-btn>
</v-flex>
</v-layout>
</form>
</v-flex>
</v-layout>
</v-container>
</v-app>
</template>
<script>
export default {
data() {
return {
title: "",
imageUrl: "",
description: "",
ingredients: "",
};
},
computed: {
formIsValid() {
return (
this.title !== "" &&
this.description !== "" &&
this.imageUrl !== "" &&
this.ingredients != ""
);
},
},
methods: {
onCreateRecipe() {
if (!this.formIsValid) {
return;
}
const recipeData = {
title: this.title,
description: this.description,
imageUrl: this.imageUrl,
ingredients: this.ingredients,
};
console.log(recipeData)
console.log("The Local Storage"+localStorage.setItem(this.recipeData));
}
}
};
</script>
<style scoped>
.btn-style {
color: #43a047;
}
.color {
color: #fafafa;
}
</style>
to store the data to localStorage, you have to define name of the storage first and then the data.
localStorage.setItem('storageName', recipeData)
to see the data of localStorage.
console.log(localStorage.getItem('StorageName'))
learn more https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
and theres no need this.recipeData because u declare the variable on the function. to get the data enought with recipeData
Local storage is a key-value data structure, you have to specify a key that will be used to retrieved the data from the storage as the first parameter. This is the syntax localStorage.setItem(keyName, keyValue);
Also, it has to be saved and retrieved as a string, stringifying it when saving and parsing it when getting it.
Your code for saving the object should be like this:
localStorage.setItem('recipeDataKey', JSON.stringify(this.recipeData));
and for retrieving:
const recipeData = JSON.parse(localStorage.setItem('recipeDataKey'));
This is a project for running a site that displays recipes and performs several operations such as creating a site, but I encountered this problem.
I have this file to create a recipe where I enter the recipe data, but how can I create an alert on this page says that creating a recipe succeeded.
How can I solve the Problem?
The data is in this file.
createRecipe.vue:
<template>
<v-app>
<v-container>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<h2 class="btn-style">Create Recipe</h2>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<form #submit.prevent="onCreateRecipe">
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="id"
label="Id"
id="id"
v-model="id"
color="#43A047"
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="title"
label="Title"
id="title"
v-model="title"
color="#43A047"
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="imageUrl"
label="ImageUrl"
id="imageUrl"
v-model="imageUrl"
color="#43A047"
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<img :src="imageUrl" height="300px">
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="description"
label="Description"
id="description"
v-model="description"
color="#43A047"
multi-line
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="ingredientsName"
label="IngredientsName"
id="ingredientsName"
v-model="ingredientsName"
color="#43A047"
multi-line
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-text-field
name="ingredientsQuantity"
label="IngredientsQuantity"
id="ingredientsQuantity"
v-model="ingredientsQuantity"
color="#43A047"
multi-line
required
>
</v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<v-btn
class="green darken-1 color"
:disabled="!formIsValid"
type="submit"
>
Create Recipe
</v-btn>
</v-flex>
</v-layout>
</form>
</v-flex>
</v-layout>
</v-container>
</v-app>
</template>
<script>
export default {
data() {
return {
id:"",
title: "",
imageUrl: "",
description: "",
ingredientsName: "",
ingredientsQuantity: "",
};
},
computed: {
formIsValid() {
return (
this.id !== ""&&
this.title !== "" &&
this.description !== "" &&
this.imageUrl !== "" &&
this.ingredientsName !== ""&&
this.ingredientsQuantity !== ""
);
}
},
methods: {
onCreateRecipe() {
if (!this.formIsValid) {
return;
}
const recipeData = {
id:this.id,
title: this.title,
description: this.description,
imageUrl: this.imageUrl,
ingredientsName: this.ingredientsName,
ingredientsQuantity: this.ingredientsQuantity
};
// Here we call the setter to put the Data inside it
this.$store.commit('createRecipe', recipeData)
const stringifiedData = JSON.stringify(recipeData);
// console.log("S: ", stringifiedData);
localStorage.setItem("recipe", stringifiedData);
console.log("We got : ", JSON.parse(localStorage.getItem("recipe")));
},
}
};
</script>
<style scoped>
.btn-style {
color: #43a047;
}
.color {
color: #fafafa;
}
</style>
You need to use async action not mutation you can not use async operations with mutations. It should look like this:
this.$store.dispatch('createRecipe', recipeData).then(() => //alert('STH') or whatever you want to do after you add recipe)
editItem(){
if(this.selected.length!=1) {
alert("Choose only one row");
} else {
//what should i put in here?
}
}
Hi, I created a datatable with selectboxs for each row using vuejs.
I created a button that when clicked activates the method above, how can I make it that when just one row is selected a form is opened and you can edit the info in that row?
I made a form that when filled and a button "addItem" is clicked the data-table will insert the row with the info in the form.
I tried using v-edit-dialog but i just cant make it work...
here is the whole code:
<style>
table th + th { border-left:1px solid #dddddd; }
table td + td { border-left:1px solid #dddddd; }
</style>
<template>
<div id="consulta">
<v-container grid-list-xl fluid>
<v-layout row wrap>
<v-flex sm12>
<v-widget title="Testando">
<div slot="widget-content">
<v-container id="teste">
<v-layout row>
<v-flex xs4>
<v-subheader>EAN</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="ean"
label=""
color="primary"
id="ean"
mask="#.######.######"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>Descrição</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="desc"
id="desc"
label=""
value=""
:rules="[(v) => v.length <= 50 || 'Max 50 characters']"
:counter="50"
single-line
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>Marca</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="marca"
label=""
color="primary"
id="marca"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>Departamento</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="dep"
label=""
color="primary"
id="dep"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>Categoria</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="categ"
label=""
color="primary"
id="categ"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>Atributos</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="att"
label=""
color="primary"
id="att"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>Loja</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="loja"
label=""
color="primary"
id="loja"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs4>
<v-subheader>URL</v-subheader>
</v-flex>
<v-flex xs8>
<v-text-field
name="url"
label=""
color="primary"
id="url"
></v-text-field>
</v-flex>
</v-layout>
<div>
<v-btn small color="primary" #click="addItem">Enviar</v-btn>
</div>
</v-container>
</div>
</v-widget>
</v-flex>
<v-flex sm12>
<h1>Tabela</h1>
</v-flex>
<v-flex lg12>
<v-toolbar card color="white">
<v-text-field
flat
solo
prepend-icon="search"
placeholder="Type something"
v-model="search"
hide-details
class="hidden-sm-and-down"
></v-text-field>
<v-btn icon>
<v-icon>filter_list</v-icon>
</v-btn>
</v-toolbar>
<v-divider></v-divider>
<v-card>
<v-card-text class="pa-0">
<v-data-table
:headers="headers"
:search="search"
:items="items"
item-key="ean"
class="elevation-1"
select-all
v-model="selected">
<template slot="items" slot-scope="props">
<td> <v-checkbox v-model="props.selected" primary hide-details></v-checkbox></td>
<td class="text-xs-center">{{ props.item.ean }}</td>
<td class="text-xs-center">{{ props.item.desc }}</td>
<td class="text-xs-center">{{ props.item.marca }}</td>
<td class="text-xs-center">{{ props.item.dep }}</td>
<td class="text-xs-center">{{ props.item.categ }}</td>
<td class="text-xs-center">{{ props.item.att }}</td>
<td class="text-xs-center">{{ props.item.loja }}</td>
<td class="text-xs-center">{{ props.item.url }}</td>
</template>
</v-data-table>
</v-card-text>
</v-card>
<div>
<v-btn color="red" #click="deleteItem">Delete</v-btn>
<v-btn color="orange" #click="editItem">Edit</v-btn>
</div>
</v-flex>
</v-layout>
</v-container>
</div>
</template>
<script>
import API from '#/api';
import EChart from '#/components/chart/echart';
import MiniStatistic from '#/components/widgets/statistic/MiniStatistic';
import PostListCard from '#/components/widgets/card/PostListCard';
import ProfileCard from '#/components/widgets/card/ProfileCard';
import PostSingleCard from '#/components/widgets/card/PostSingleCard';
import WeatherCard from '#/components/widgets/card/WeatherCard';
import PlainTable from '#/components/widgets/list/PlainTable';
import PlainTableOrder from '#/components/widgets/list/PlainTableOrder';
import VWidget from '#/components/VWidget';
import Material from 'vuetify/es5/util/colors';
import VCircle from '#/components/circle/VCircle';
import BoxChart from '#/components/widgets/chart/BoxChart';
import ChatWindow from '#/components/chat/ChatWindow';
import CircleStatistic from '#/components/widgets/statistic/CircleStatistic';
import LinearStatistic from '#/components/widgets/statistic/LinearStatistic';
export default {
layout: 'dashboard',
components: {
VWidget,
MiniStatistic,
ChatWindow,
VCircle,
WeatherCard,
PostSingleCard,
PostListCard,
ProfileCard,
EChart,
BoxChart,
CircleStatistic,
LinearStatistic,
PlainTable,
PlainTableOrder
},
data() {
return{
search: '',
selected: [],
headers:[
{text:'EAN', value:'ean', sortable: true, align:"center"},
{text:'Descrição', value:'desc', sortable: true, align:"center"},
{text:'Marca', value:'marca', sortable: true, align:"center"},
{text:'Departamento', value:'dep', sortable: true, align:"center"},
{text:'Categoria', value:'categ', sortable: true, align:"center"},
{text:'Atributos', value:'att', sortable: true, align:"center"},
{text:'Loja', value:'loja', sortable: true, align:"center"},
{text:'URL', value:'url', sortable: true, align:"center"},
],
items:[{
ean: '9234858583',
desc: 'Item teste',
marca: 'Danone',
dep: 'Comida?',
categ: 'Laticinio',
att: 'Yogurt',
loja: 'Mercadinho',
url: 'www.mercadinho.fakeaddress.com',
}],
}
},
methods: {
addItem(){
if(document.querySelector("#ean").value!=""&&
document.querySelector("#desc").value!=""&&
document.querySelector("#marca").value!=""&&
document.querySelector("#dep").value!=""&&
document.querySelector("#categ").value!=""&&
document.querySelector("#att").value!=""&&
document.querySelector("#loja").value!=""&&
document.querySelector("#url").value!=""){
let registro = {
"ean": document.querySelector("#ean").value,
"desc": document.querySelector("#desc").value,
"marca":document.querySelector("#marca").value,
"dep": document.querySelector("#dep").value,
"categ": document.querySelector("#categ").value,
"att": document.querySelector("#att").value,
"loja": document.querySelector("#loja").value,
"url": document.querySelector("#url").value,
};
this.insert(registro);
this.items.push(registro)
}
else{
alert("Um ou mais campos não foram preenchidos!");
}
},
editItem(){
if(this.selected.length){
alert("Select just one row")
}
else{
//show form to edit the info
}
},
deleteItem(){
if(confirm("Deseja deletar tais fileiras?")){
for(var i = 0; i < this.selected.length; i++){
const index = this.items.indexOf(this.selected[i]);
this.items.splice(index, 1);
}
}
}
}
}
</script>
Since you're using Vuetify as your Material Design Framework you could use the Dialog Component. You can find many Example in the official documentation: https://vuetifyjs.com/en/components/dialogs#form
How Do I resolve this. I am getting the error Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. This error is being printed on the console as I run the app. When it does this , the nothing is displayed on on the views its just blank.
<template>
<v-container id="dashboard" fluid grid-list-lg class="mx- pa-7">
<v-layout row wrap>
<v-flex md3 sm6 xs12>
<v-card class="cyan darken-3" l light>
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">Income Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalUsers}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
<v-flex md3 sm6 xs12>
<v-card class="blue-grey darken-1">
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">Today's Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalAmount}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
<v-flex md3 sm6 xs12>
<v-card class="pink lighten-4">
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">Yesterday's Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalUsersThis}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
<v-flex md3 sm6 xs12>
<v-card class="blue-grey darken-1">
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">This Week's Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalAmountThis}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
</v-layout>
<v-layout class="pt-1" row wrap>
<v-flex md4 xs12>
<v-card light>
<doughnut></doughnut>
</v-card>
</v-flex>
<v-flex md4 xs12>
<v-card light>
<bar></bar>
</v-card>
</v-flex>
<v-flex md4 xs12>
<v-card light class="Chart">
<line-chart></line-chart>
</v-card>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs7>
<v-card>
<v-card-title>
Recent Transactions
<v-spacer/> <v-spacer/>
<v-text-field name="product" label="Search" light v-model="searchTransaction"></v-text-field>
</v-card-title>
<v-data-table v-bind:headers="headers" v-bind:items="items" v-bind:search="search"
v-bind:pagination.sync="pagination" hide-actions
class="elevation-1">
<template slot="items" slot-scope="props" class="body-2" >
<td class="body-2" >{{ props.item.account_from }}</td>
<td class="text-xs-left">{{ props.item.amount }}</td>
<td class="text-xs-left">{{ props.item.transaction_code}}</td>
<td class="text-xs-left">{{ props.item.payment_mode}}</td>
<td class="text-xs-left">{{ props.item.ref}}</td>
<td class="text-xs-left">{{ props.item.status}}
</td>
<td class="text-xs-left">{{ props.item.date}}</td>
<!-- <td class="text-xs-left">{{ props.item.quantity}}</td>
<td class="text-xs-left"><img :src='getImageURL(props.item.Product.phone_number)' height="90dp" width="90dp"/></td>
<td class="text-xs-left">
<v-btn fab small dark class="teal" #click.native="edit()">
<v-icon>edit</v-icon>
</v-btn>
<v-btn fab small class="cyan" #click.native="remove(props.item)">
<v-icon>delete</v-icon>
</v-btn>
</td>-->
</template>
</v-data-table>
<div class="text-xs-center pt-2">
<v-pagination v-model="pagination.page" :length="pages" circle></v-pagination>
</div>
</v-card>
</v-flex>
<v-flex xs5>
<v-card>
<v-card-title>
Merchants
<v-spacer/> <v-spacer/>
<v-text-field name="product" label="Search" light v-model="productSearch"></v-text-field>
</v-card-title>
<v-data-table v-bind:headers="headers2" v-bind:items="businesses" v-bind:search="search"
v-bind:pagination.sync="pagination2" hide-actions
class="elevation-1"
:loading="false">
<v-progress-linear slot="progress" color="blue" indeterminate></v-progress-linear>
<template slot="items" slot-scope="props" class="body-2" >
<td class="body-2" >{{ props.item.business_name }}</td>
<td class="text-xs-left">{{ props.item.short_code }}</td>
<td class="text-xs-left">{{ props.item.sender_id}}</td>
<!--<td class="text-xs-left">{{ props.item.payment_mode}}</td>
<td class="text-xs-left">KES {{ props.item.transaction_ref}}</td>
<td class="text-xs-left">KES {{ props.item.date}}</td>-->
<!-- <td class="text-xs-left">{{ props.item.quantity}}</td>
<td class="text-xs-left"><img :src='getImageURL(props.item.Product.phone_number)' height="90dp" width="90dp"/></td>
<td class="text-xs-left">
<v-btn fab small dark class="teal" #click.native="edit()">
<v-icon>edit</v-icon>
</v-btn>
<v-btn fab small class="cyan" #click.native="remove(props.item)">
<v-icon>delete</v-icon>
</v-btn>
</td>-->
</template>
</v-data-table>
<div class="text-xs-center pt-2">
<v-pagination v-model="pagination2.page" :length="pages2" circle></v-pagination>
</div>
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import Bar from "../components/chart/Bar";
import Doughnut from "../components/chart/Doughnut";
import LineChart from "../components/chart/LineChart";
import { execute } from '../api'
export default {
name: "Dashboard",
components: {
Bar,
Doughnut,
LineChart
},
data () {
return {
searchTransaction:'',
items:[],
businesses:[],
totalUsers:'',
totalAmount:'',
totalUsersThis:'',
totalAmountThis:'',
search: '',
pagination: [],
pagination2: [],
productSearch:'',
headers: [
{
text: 'Phone Number',
left: true,
sortable: false,
value: 'phone_number'
},
{ text: 'Amount', value: 'amount' , sortable: false,},
{ text: 'Transaction Code', value: 'transaction_code' , sortable: false,},
{ text: 'Payment Mode', value: 'payment_mode' , sortable: false},
{ text: 'Transaction ref', value: 'transaction_ref' , sortable: false},
{ text: 'Status', value: 'status' , sortable: false},
{ text: 'date', value: 'date' , sortable: false}
], headers2: [
{
text: 'Business',
left: true,
sortable: false,
value: 'business'
},
{ text: 'ShortCode', value: 'short_code' , sortable: false,},
{ text: 'Sender ID', value: 'sender_id' , sortable: false,},
]
};
},
watch: {
searchTransaction: function() {
this.getTransactions();
}
},
methods: {
getCustomers () {
const data = new FormData()
data.append('TransactionType', 'getDashboardData')
execute(data).then((res) => {
this.totalUsers= new Intl.NumberFormat().format(res.data.data.IncomeRevenue)
this.totalAmount= new Intl.NumberFormat().format(res.data.data.TodayRevenue)
this.totalUsersThis= new Intl.NumberFormat().format(res.data.data.YesterdayRevenue)
this.totalAmountThis= new Intl.NumberFormat().format(res.data.data.ThisWeekRevenue)
}).catch((e) => {
// TODO
})
},
getTransactions () {
const data = new FormData()
data.append('TransactionType', 'getRecentTransactions')
data.append('keyword',this.searchTransaction)
execute(data).then((res) => {
this.items = res.data.data
}).catch((e) => {
// TODO
})
}, getBusinesses () {
const data = new FormData()
data.append('TransactionType', 'getBusinesses')
execute(data).then((res) => {
this.businesses = res.data.data
}).catch((e) => {
// TODO
})
}
},
computed: {
pages () {
return this.pagination && this.pagination.rowsPerPage ? Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage) : 0
},
pages2 () {
return this.pagination2 && this.pagination2.rowsPerPage ? Math.ceil(this.pagination2.totalItems / this.pagination2.rowsPerPage) : 0
}
},
mounted () {
this.getCustomers()
this.getTransactions()
this.getBusinesses()
}
};
</script>
<!--<style scoped>
#dashboard .flex {
margin-bottom: 2px;
}
</style>-->
Since you're using lots of <v-flex> elements in your code, my guess is you just made a typo and accidentally created a <x-flex> element. Just fix the typo (change all the x-flex to v-flex in your code) and it will work