2018-09-17

昨天看了vue基礎(chǔ):
{{msg}} v-text v-html
事件:@click
雙向綁定 v-model
屬性綁定title
計算屬性:computed
偵聽器:watch
v-if v-show v-for (key值)
局部樣式(加scoped) 全局樣式
組件間通信:
父組件-》子組件 父組件通過屬性傳給子組件,子組件通過props接受,
子組件-》 父組件 子組件通過this.$emit()發(fā)布訂閱, 父組件采用監(jiān)聽的方式,
通過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>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • # 傳智播客vue 學(xué)習(xí)## 1. 什么是 Vue.js* Vue 開發(fā)手機(jī) APP 需要借助于 Weex* Vu...
    再見天才閱讀 3,789評論 0 6
  • 這篇筆記主要包含 Vue 2 不同于 Vue 1 或者特有的內(nèi)容,還有我對于 Vue 1.0 印象不深的內(nèi)容。關(guān)于...
    云之外閱讀 5,175評論 0 29
  • 前言 您將在本文當(dāng)中了解到,往網(wǎng)頁中添加數(shù)據(jù),從傳統(tǒng)的dom操作過渡到數(shù)據(jù)層操作,實現(xiàn)同一個目標(biāo),兩種不同的方式....
    itclanCoder閱讀 26,241評論 1 12
  • 二十年,之于浩蕩歷史,只是短短一瞬間。 二十年,之于一座城市,卻是說不盡的滄桑巨變。 歲月不居,天道酬勤。二十年前...
    未梳妝閱讀 427評論 0 0
  • (念一次假期和老友出行湛江) 南方的清晨一定很溫和吧! 至少也不會如北方凄清吧! 當(dāng)初海邊的追光少年, 如今又是天...
    禰笛閱讀 439評論 0 2

友情鏈接更多精彩內(nèi)容