美文网首页
08-1 vuex-notebar.vue

08-1 vuex-notebar.vue

作者: 时修七年 | 来源:发表于2019-02-26 20:48 被阅读0次
<template>
  <div class="notes">
    <div class="notebar">
      <notebar @setCurNote="setNote"></notebar>
    </div>
    <div class="content">
      <div class="topbar">
        <span>创建时间: </span><Time :time="curNote.createdAt||new Date()" :interval="1" />
        <span>修改时间: </span><Time :time="curNote.updatedAt||new Date()" :interval="1" />
        <Button class='delete' type="error" size="small" @click.native='onDelete'>删除</Button>
        <span class='belong'>{{statusText}}</span>
      </div>
      <div class="title">
        <input type="text" v-model="curNote.title" @input="saveNote(),statusText='正在修改...'">
      </div>
      <mavon-editor
        v-model="curNote.content"
        :toolbarsFlag = 'false'
        @change="saveNote(),statusText='正在修改...'"/>
    </div>
  </div>
</template>
<script>

import notebar from './Notebar'
import Notebook from '../apis/Notebooks'
import Note from '../apis/Notes'
import debounce from 'debounce';
import { mapGetters, mapState, mapActions } from 'Vuex';
export default {
  components: {
    notebar
  },
  data() {
    return {
      notes: [],
      content: "",
      statusText: "已保存",
    }
  },
  computed: {
    ...mapGetters(['curNote'])
  },
  methods: {
    ...mapActions(['updateNote','deleteNote']),
    setNote(){
      console.log(arguments)
      this.curNote = arguments[0],
      this.notes = arguments[1]
    },
    onDelete(){
      this.deleteNote({noteId:this.curNote.id})
    },
    saveNote: debounce(function(){
      this.updateNote({noteId:this.curNote.id,title:this.curNote.title,content:this.curNote.content}).then(res=>{
       console.log('保存')
       this.statusText = '已保存'
      }).catch(err=>{
        this.statusText = '保存失败'
        this.$Message.error(err.msg)
      })
    },1500),
  }
}
</script>

<style lang="less" scoped>
  .notes {
    margin: -16px;
    height: calc(~'100vh - 60px');
    .notebar {
      width: 220px;
      height: 100%;
      border-right: 2px solid #ccc
    }
    .content {
      position: absolute;
      margin-left: 221px;
      top: 0;
      width: 940px;
      height: 800px;
      padding: 0;
      .topbar {
        height: 50px;
        padding: 18px;
        border-bottom: 1px solid #eee;
        background: #fff;
        .belong ,.delete{
          float: right
        }
        .delete {
          margin-top: -3px;
          margin-left: 16px;
        }
      }
      .title {
        input {
          width: 100%;
          border: none;
          outline: none;
          font-size: 26px;
          padding-left: 15px;
          background: #f8f8f9
        }
      }
    }
  }
</style>






相关文章

  • 08-1 vuex-notebar.vue

  • 08-1 上善若水

    老子智慧和领导艺术之08-1 “上善若水,水善利万物而不争,处众人之所恶,故几于道”出自第08章,意思是说至能顶好...

  • 08-1 上善若水

    08-1 上善若水,出自第08章,意思是说 顶好的行为类似水。 至高顶好的利于他的能力和行为可以用水为例加以说明。...

  • 08-1 上善若水

    08-1 “上善若水水善利万物而不争处众人之所恶故几于道”出自《道德经》第八章,意思是说:顶好至高的善举,能力和行...

  • 08-4复盘

    总结:08-1、08-2、08-3 无论你是学生还是进入职场的人士,自学都会是我们必须要掌握的一门技能。 而面对自...

  • 08-1“上善若水水善利万物而不争处众人之所恶故几于道”出自《道

    08-1 “上善若水水善利万物而不争处众人之所恶故几于道”出自《道德经》第08章,意思是说 :顶好的行为类似水。因...

  • 凡|梵 08-1:无法想象的壮阔

    文:榛苓 摄影:小淑女 金刚 半夜里,电褥子把小淑女干醒,喝水回床的路上,踢乱了插线板。我们屋断电了。收拾好...

  • 08-1为什么要掌握高效阅读技巧

    别人一小时就能学会和掌握理解透彻的事情,我却要好几天才能做到,甚至可能是当下做到了,过几天还是给忘记了。 因为你在...

  • 前端面试08-1:说一下 web worker

    在 HTML 页面中,如果在执行脚本时,页面的状态是不可相应的,直到脚本执行完成后, 页面才变成可相应。web w...

网友评论

      本文标题:08-1 vuex-notebar.vue

      本文链接:https://www.haomeiwen.com/subject/fgwzyqtx.html