2018-09-17

昨天看了vue基础:
{{msg}} v-text v-html
事件:@click
双向绑定 v-model
属性绑定title
计算属性:computed
侦听器:watch
v-if v-show v-for (key值)
局部样式(加scoped) 全局样式
组件间通信:
父组件-》子组件 父组件通过属性传给子组件,子组件通过props接受,
子组件-》 父组件 子组件通过this.$emit()发布订阅, 父组件采用监听的方式,
通过vue-cli写个todolist(只有增删功能)

<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <div>
      <input v-model="inputValue"/>
      <button @click="handleSubmit">提交</button>
    </div>
    <ul>
      <todo-item 
        v-for="(item,index) of lists"
        :content="item"
        :index="index"
        :key="index"
        @delete="handleDelete"
      >
      </todo-item>
    </ul>
  </div>
</template>

<script>
import TodoItem from "./components/TodoItem.vue";

export default {
  name: "app",
  components: {
    "todo-item": TodoItem
  },
  data() {
    return {
      inputValue: "",
      lists: []
    };
  },
  methods: {
    handleSubmit() {
      this.lists.push(this.inputValue);
      this.inputValue = "";
    },
    handleDelete(index) {
      this.lists = this.lists.filter(item => {
        return item !== this.lists[index];
      });
    }
  }
};
</script>

<template>
  <li @click="handleDelete">{{content}}</li>
</template>

<script>
export default {
  props: ['content', 'index'],
  methods: {
    handleDelete: function(){
      this.$emit('delete',this.index)
    }
  }
}
</script>
<style scoped>

</style>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • # 传智播客vue 学习## 1. 什么是 Vue.js* Vue 开发手机 APP 需要借助于 Weex* Vu...
    再见天才阅读 3,702评论 0 6
  • 这篇笔记主要包含 Vue 2 不同于 Vue 1 或者特有的内容,还有我对于 Vue 1.0 印象不深的内容。关于...
    云之外阅读 5,095评论 0 29
  • 前言 您将在本文当中了解到,往网页中添加数据,从传统的dom操作过渡到数据层操作,实现同一个目标,两种不同的方式....
    itclanCoder阅读 26,015评论 1 12
  • 二十年,之于浩荡历史,只是短短一瞬间。 二十年,之于一座城市,却是说不尽的沧桑巨变。 岁月不居,天道酬勤。二十年前...
    未梳妆阅读 380评论 0 0
  • (念一次假期和老友出行湛江) 南方的清晨一定很温和吧! 至少也不会如北方凄清吧! 当初海边的追光少年, 如今又是天...
    祢笛阅读 397评论 0 2