Skip to content

Commit be357fc

Browse files
committed
feat(core): make it more like react hooks
1 parent 02bac55 commit be357fc

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/components/item/item.vue

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { reactive, toRefs } from 'vue';
2+
import { ref } from 'vue';
33
44
export default {
55
props: {
@@ -9,22 +9,21 @@ export default {
99
}
1010
},
1111
setup(props, { emit }) {
12-
const state = reactive({
13-
editing: false,
14-
name: props.todo.name
15-
});
12+
const editing = ref(false);
13+
const name = ref(props.todo.name);
1614
17-
const handleRemove = () => emit('remove', props.todo.id);
15+
const handleEdit = () => (editing.value = true);
1816
const handleCompleted = () => emit('update', { id: props.todo.id, completed: !props.todo.completed });
19-
const handleEdit = () => (state.editing = true);
20-
const handleChange = event => (state.name = event.target.value);
17+
const handleRemove = () => emit('remove', props.todo.id);
18+
const handleChange = event => (name.value = event.target.value);
2119
const handleBlur = () => {
22-
emit('update', { id: props.todo.id, name: state.name });
23-
state.editing = false;
20+
emit('update', { id: props.todo.id, name: name.value });
21+
editing.value = false;
2422
};
2523
2624
return {
27-
...toRefs(state),
25+
name,
26+
editing,
2827
handleRemove,
2928
handleCompleted,
3029
handleEdit,

0 commit comments

Comments
 (0)