Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
T
To do list
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bui Duc Tuan
To do list
Commits
b5a5e77f
Commit
b5a5e77f
authored
Mar 10, 2022
by
Bui Duc Tuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix create component product
parent
2fc5a026
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
60 deletions
+41
-60
Index.vue
src/components/product/Index.vue
+10
-14
addProduct.vue
src/components/product/addProduct.vue
+13
-22
editProduct.vue
src/components/product/editProduct.vue
+18
-24
No files found.
src/components/product/Index.vue
View file @
b5a5e77f
...
@@ -29,11 +29,11 @@
...
@@ -29,11 +29,11 @@
<router-link
<router-link
tag=
"span"
tag=
"span"
class=
"icon_action icon_edit"
class=
"icon_action icon_edit"
:to=
"
{ name: 'editProduct', params: { id: i
ndex
} }"
:to=
"
{ name: 'editProduct', params: { id: i
tem.id
} }"
>
>
<ion-icon
name=
"create-outline"
></ion-icon>
<ion-icon
name=
"create-outline"
></ion-icon>
</router-link>
</router-link>
<span
class=
"icon_action icon_del"
@
click=
"removeProduct(i
ndex
)"
<span
class=
"icon_action icon_del"
@
click=
"removeProduct(i
tem.id
)"
><ion-icon
name=
"trash-outline"
></ion-icon
><ion-icon
name=
"trash-outline"
></ion-icon
></span>
></span>
</td>
</td>
...
@@ -60,22 +60,18 @@ export default {
...
@@ -60,22 +60,18 @@ export default {
};
};
},
},
mounted
:
function
()
{
created
:
function
()
{
if
(
!
localStorage
.
getItem
(
"
products
"
))
{
let
uri
=
`http://127.0.0.1:8000/api/products/`
;
this
.
axios
.
get
(
"
http://127.0.0.1:8000/api/products/
"
).
then
((
response
)
=>
{
this
.
axios
.
get
(
uri
).
then
((
response
)
=>
{
this
.
products
=
response
.
data
this
.
products
=
response
.
data
;
localStorage
.
setItem
(
"
products
"
,
JSON
.
stringify
(
this
.
products
));
});
});
}
else
{
this
.
products
=
JSON
.
parse
(
localStorage
.
getItem
(
"
products
"
));
}
},
},
methods
:
{
methods
:
{
removeProduct
(
i
ndex
)
{
removeProduct
(
i
d
)
{
if
(
confirm
(
"
Are you sure you want to delete products?
"
))
{
if
(
confirm
(
"
Are you sure you want to delete products?
"
))
{
this
.
products
.
splice
(
index
,
1
)
;
let
uri
=
`http://127.0.0.1:8000/api/products/
${
id
}
`
;
localStorage
.
setItem
(
"
products
"
,
JSON
.
stringify
(
this
.
products
)
);
this
.
axios
.
delete
(
uri
);
this
.
$alertify
.
error
(
"
Delete product successfully
"
);
this
.
$alertify
.
error
(
"
Delete product successfully
"
);
}
}
},
},
...
...
src/components/product/addProduct.vue
View file @
b5a5e77f
...
@@ -43,40 +43,31 @@ Vue.use(VueAlertify);
...
@@ -43,40 +43,31 @@ Vue.use(VueAlertify);
export
default
{
export
default
{
data
:
function
()
{
data
:
function
()
{
return
{
return
{
name
:
''
,
name
:
""
,
color
:
''
,
color
:
""
,
price
:
''
,
price
:
""
,
product
s
:
[]
,
product
:
{}
,
};
};
},
},
created
:
function
()
{
if
(
localStorage
.
getItem
(
"
products
"
))
{
this
.
products
=
JSON
.
parse
(
localStorage
.
getItem
(
"
products
"
));
}
},
methods
:
{
methods
:
{
submit
()
{
submit
()
{
if
(
this
.
name
==
""
||
this
.
price
==
""
||
this
.
color
==
""
)
{
if
(
this
.
name
==
''
||
this
.
price
==
''
||
this
.
color
==
''
)
{
alert
(
"
Please fill it out completely form!!
"
);
alert
(
"
Please fill it out completely form!!
"
);
return
;
return
;
}
else
if
(
isNaN
(
this
.
price
))
{
}
else
if
(
isNaN
(
this
.
price
))
{
alert
(
"
price only accepts numeric data!!
"
);
alert
(
"
price only accepts numeric data!!
"
);
return
;
return
;
}
}
this
.
product
.
name
=
this
.
name
;
this
.
product
.
color
=
this
.
color
;
this
.
product
.
price
=
this
.
price
;
this
.
products
.
push
({
let
uri
=
`http://127.0.0.1:8000/api/products/`
;
name
:
this
.
name
,
this
.
axios
.
post
(
uri
,
this
.
product
)
color
:
this
.
color
,
price
:
this
.
price
});
localStorage
.
setItem
(
"
products
"
,
JSON
.
stringify
(
this
.
products
));
this
.
name
=
''
;
this
.
color
=
''
;
this
.
price
=
''
;
this
.
$router
.
push
({
name
:
'
product
'
});
this
.
$router
.
push
({
name
:
'
product
'
});
this
.
$alertify
.
success
(
"
Add
task
successfully
"
);
this
.
$alertify
.
success
(
"
Add
product
successfully
"
);
},
},
},
},
};
};
...
...
src/components/product/editProduct.vue
View file @
b5a5e77f
...
@@ -47,25 +47,20 @@ export default {
...
@@ -47,25 +47,20 @@ export default {
name
:
""
,
name
:
""
,
color
:
""
,
color
:
""
,
price
:
""
,
price
:
""
,
product
s
:
[]
,
product
:
null
,
};
};
},
},
created
:
function
()
{
created
:
function
()
{
if
(
localStorage
.
getItem
(
"
products
"
))
{
let
uri
=
`http://127.0.0.1:8000/api/products/
${
this
.
id
}
`
;
this
.
products
=
JSON
.
parse
(
localStorage
.
getItem
(
"
products
"
));
this
.
axios
.
get
(
uri
).
then
((
response
)
=>
{
}
this
.
product
=
response
.
data
;
},
this
.
name
=
this
.
product
.
name
;
created
:
function
()
{
this
.
color
=
this
.
product
.
color
;
this
.
products
=
JSON
.
parse
(
localStorage
.
getItem
(
"
products
"
));
this
.
price
=
this
.
product
.
price
;
}).
catch
(()
=>
{
if
(
this
.
products
[
this
.
id
])
{
this
.
$router
.
push
(
"
/product
"
);
this
.
name
=
this
.
products
[
this
.
id
].
name
;
this
.
$alertify
.
error
(
'
Product not found!
'
);
this
.
color
=
this
.
products
[
this
.
id
].
color
;
});
this
.
price
=
this
.
products
[
this
.
id
].
price
;
}
else
{
this
.
$router
.
push
(
"
/product
"
);
this
.
$alertify
.
error
(
'
Product not found!
'
);
}
},
},
methods
:
{
methods
:
{
submit
()
{
submit
()
{
...
@@ -77,16 +72,15 @@ export default {
...
@@ -77,16 +72,15 @@ export default {
return
;
return
;
}
}
this
.
products
[
this
.
id
].
name
=
this
.
name
this
.
product
.
name
=
this
.
name
;
this
.
products
[
this
.
id
].
color
=
this
.
color
this
.
product
.
color
=
this
.
color
;
this
.
products
[
this
.
id
].
price
=
this
.
price
this
.
product
.
price
=
this
.
price
;
let
uri
=
`http://127.0.0.1:8000/api/products/
${
this
.
id
}
`
;
this
.
axios
.
put
(
uri
,
this
.
product
);
localStorage
.
setItem
(
"
products
"
,
JSON
.
stringify
(
this
.
products
));
this
.
name
=
""
;
this
.
color
=
""
;
this
.
price
=
""
;
this
.
$router
.
push
({
name
:
"
product
"
});
this
.
$router
.
push
({
name
:
"
product
"
});
this
.
$alertify
.
warning
(
"
Add task
successfully
"
);
this
.
$alertify
.
warning
(
"
Edit product
successfully
"
);
},
},
},
},
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment