MyHeader.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div class="todo-header">
  3. <input type="text" @keyup.enter="add" v-model="title" placeholder="请输入你的任务名称,按回车键确认"/>
  4. </div>
  5. </template>
  6. <script>
  7. import {nanoid} from 'nanoid'
  8. export default {
  9. name: "MyHeader",
  10. data(){
  11. return{
  12. title:''
  13. }
  14. },
  15. methods: {
  16. add() {
  17. // 校验数据
  18. if(!this.title.trim()) return alert('输入不能为空')
  19. //console.log(e.target.value);
  20. //将用户的输入包装成一个todo对象
  21. const todoObj = {id:nanoid(),title:this.title,done:false}
  22. // console.log(todoObj)
  23. // 通知App组件去添加一个todo对象
  24. this.$emit('addTodo',todoObj)
  25. // 情况输入
  26. this.title = ''
  27. },
  28. },
  29. };
  30. </script>
  31. <style scoped>
  32. /*header*/
  33. .todo-header input {
  34. width: 560px;
  35. height: 28px;
  36. font-size: 14px;
  37. border: 1px solid #ccc;
  38. border-radius: 4px;
  39. padding: 4px 7px;
  40. }
  41. .todo-header input:focus {
  42. outline: none;
  43. border-color: rgba(82, 168, 236, 0.8);
  44. box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),
  45. 0 0 8px rgba(82, 168, 236, 0.6);
  46. }
  47. </style>