欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue監(jiān)聽用戶輸入和點(diǎn)擊功能

 更新時(shí)間:2019年09月27日 12:00:43   作者:小羽向前跑  
這篇文章主要為大家詳細(xì)介紹了vue監(jiān)聽用戶輸入和點(diǎn)擊功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue監(jiān)聽用戶輸入和點(diǎn)擊的具體代碼,供大家參考,具體內(nèi)容如下

功能1:監(jiān)聽用戶輸入和點(diǎn)擊,并實(shí)時(shí)顯示,

功能2:點(diǎn)擊發(fā)布,編輯頁面隱藏,顯示發(fā)布成功。

功能1 html代碼:

使用:v-model監(jiān)聽,!submmited視圖默認(rèn)顯示,注意監(jiān)聽option v-for="(i,index) in authors"   v-bind:value="authors[index],

監(jiān)聽當(dāng)下用戶點(diǎn)擊的那個(gè);

 <div id="add-blog">
  <h2>添加博客</h2>
  <form v-if="!submmited">
  <label for="" class="">博客標(biāo)題</label>
  <input class="" type="text" v-model="blog.title" required/>
  <br/>
  <label for="" class="">博客內(nèi)容</label>
  <textarea class="" v-model="blog.content"></textarea>
  <div id="checkboxs">
   <label for="">Vue.js</label>
   <input type="checkbox" value="vue.js" v-model="blog.categories"/>
   <label for="">react.js</label>
   <input type="checkbox" value="react.js" v-model="blog.categories"/>
   <label for="">javasript</label>
   <input type="checkbox" value="javasript.js" v-model="blog.categories"/>
   <label for="">css</label>
   <input type="checkbox" value="css" v-model="blog.categories"/>
  </div>
  <label for="">作者:</label>
  <select v-model="blog.author">
   <option v-for="(i,index) in authors" v-bind:value="authors[index]">
   {{i}}
   </option>
  </select>
  <button v-on:click.prevent="post">添加博客</button>
  </form>
  <hr/>
  <div id="preview">
  <h3>博客總覽</h3>
  <p>博客標(biāo)題:</p>
  <p class="color">{{blog.title}}</p>
  <p>博客內(nèi)容:</p>
  <p class="color">{{blog.content}}</p>
  <p>博客分類</p>
  <ul>
   <li v-for="categories in blog.categories" class="color">
   {{categories}}
   </li>
  </ul>
  <p>作者:</p>
  <p class="color">{{blog.author}}</p>
  </div>
 </div>

 功能1 js代碼:

data(){
   return{
   blog:{
    title:"",
    content:"",
    categories:[],
    author:""
   },
   authors:[
    "張三","李四","王五"
   ],
   submmited:false
   }
  },
 methods:{
   post:function () {
   this.$http.post("https://jsonplaceholder.typicode.com/posts/"{
    title:this.blog.title,
    body:this.blog.content,
})
   .then(function (data) {
    //console.log(data);
   })
   }
  }

功能2 html代碼:

 <div v-if="submmited">
  <h3>您的博客發(fā)布成功</h3>
 </div>

功能2 js代碼

this.submmited=true 讓 “您的博客發(fā)布成功” 顯示

methods:{
   post:function () {
   this.$http.post("https://jsonplaceholder.typicode.com/posts/"{
    title:this.blog.title,
    body:this.blog.content,
})
   .then(function (data) {
    //console.log(data);
    this.submmited=true
   })
   }
  }

addblog.vue所有代碼:

<template>
 <div id="add-blog">
  <h2>添加博客</h2>
  <form v-if="!submmited">
  <label for="" class="">博客標(biāo)題</label>
  <input class="" type="text" v-model="blog.title" required/>
  <br/>
  <label for="" class="">博客內(nèi)容</label>
  <textarea class="" v-model="blog.content"></textarea>
  <div id="checkboxs">
   <label for="">Vue.js</label>
   <input type="checkbox" value="vue.js" v-model="blog.categories"/>
   <label for="">react.js</label>
   <input type="checkbox" value="react.js" v-model="blog.categories"/>
   <label for="">javasript</label>
   <input type="checkbox" value="javasript.js" v-model="blog.categories"/>
   <label for="">css</label>
   <input type="checkbox" value="css" v-model="blog.categories"/>
  </div>
  <label for="">作者:</label>
  <select v-model="blog.author">
   <option v-for="(i,index) in authors" v-bind:value="authors[index]">
   {{i}}
   </option>
  </select>
  <button v-on:click.prevent="post">添加博客</button>
  </form>
  <div v-if="submmited">
  <h3>您的博客發(fā)布成功</h3>
  </div>
  <hr/>
  <div id="preview">
  <h3>博客總覽</h3>
  <p>博客標(biāo)題:</p>
  <p class="color">{{blog.title}}</p>
  <p>博客內(nèi)容:</p>
  <p class="color">{{blog.content}}</p>
  <p>博客分類</p>
  <ul>
   <li v-for="categories in blog.categories" class="color">
   {{categories}}
   </li>
  </ul>
  <p>作者:</p>
  <p class="color">{{blog.author}}</p>
  </div>
 </div>
</template>
 
<script>
 export default {
  name: "addblog",
  data(){
   return{
   blog:{
    title:"",
    content:"",
    categories:[],
    author:""
   },
   authors:[
    "張三","李四","王五"
   ],
   submmited:false
   }
  },
  methods:{
   post:function () {
   this.$http.post("https://jsonplaceholder.typicode.com/posts/",this.blog)
   .then(function (data) {
    console.log(data);
    this.submmited=true
   })
   }
  }
 }
</script>
 
<style scoped>
#add-blog *{
 box-sizing: border-box;
}
#add-blog{
 margin: 20px auto;
 max-width: 600px;
 padding:20px;
}
 label{
 display: block;
 margin:20px 0 10px;
 }
 input[type="text"],textarea,select{
 display: block;
 width: 100%;
 padding: 8px;
 }
 textarea{
 height: 200px;
 }
 #checkboxs label{
 display: inline-block;
 margin-top: 0;
 }
 #checkboxs input{
 display: inline-block;
 margin-right: 10px;
 }
 button{
 display: block;
 margin:20px 0;
 background: crimson;
 border:0;
 padding:14px;
 border-radius: 4px;
 font-size: 18px;
 cursor: pointer;
 color: white;
 }
 #preview{
 padding:10px 20px;
 border: 1px dotted #ccc;
 margin:30px 0;
 }
 .color{
 color: blue;
 }
</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue記住滾動(dòng)條和實(shí)現(xiàn)下拉加載的完美方法

    Vue記住滾動(dòng)條和實(shí)現(xiàn)下拉加載的完美方法

    這篇文章主要給大家介紹了關(guān)于Vue記住滾動(dòng)條和實(shí)現(xiàn)下拉加載的完美方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • 深入了解Vue中雙向數(shù)據(jù)綁定原理

    深入了解Vue中雙向數(shù)據(jù)綁定原理

    vue是一個(gè)mvvm框架,即數(shù)據(jù)雙向綁定,即當(dāng)數(shù)據(jù)發(fā)生變化的時(shí)候,視圖也就發(fā)生變化,當(dāng)視圖發(fā)生變化的時(shí)候,數(shù)據(jù)也會(huì)跟著同步變化。本文將通過示例詳解其中原理,需要的可以參考一下
    2022-05-05
  • element-ui圖片上傳組件查看和限制方式

    element-ui圖片上傳組件查看和限制方式

    這篇文章主要介紹了關(guān)于element-ui圖片上傳組件查看和限制方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Vue3中實(shí)現(xiàn)網(wǎng)頁時(shí)鐘功能(顯示當(dāng)前時(shí)間并每秒更新一次)

    Vue3中實(shí)現(xiàn)網(wǎng)頁時(shí)鐘功能(顯示當(dāng)前時(shí)間并每秒更新一次)

    本文將詳細(xì)介紹如何在Vue3中實(shí)現(xiàn)一個(gè)每秒鐘自動(dòng)更新的網(wǎng)頁時(shí)鐘,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-07-07
  • 使用vue-virtual-scroller遇到的問題及解決

    使用vue-virtual-scroller遇到的問題及解決

    這篇文章主要介紹了使用vue-virtual-scroller遇到的問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 通過vue方式實(shí)現(xiàn)二維碼掃碼功能

    通過vue方式實(shí)現(xiàn)二維碼掃碼功能

    這篇文章給大家介紹了通過vue的方式,實(shí)現(xiàn)掃碼功能,實(shí)現(xiàn)步驟分為兩步,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2021-11-11
  • Vue2.0父組件與子組件之間的事件發(fā)射與接收實(shí)例代碼

    Vue2.0父組件與子組件之間的事件發(fā)射與接收實(shí)例代碼

    這篇文章主要介紹了Vue2.0父組件與子組件之間的事件發(fā)射與接收實(shí)例代碼,需要的朋友可以參考下
    2017-09-09
  • Vue中slot的使用詳解

    Vue中slot的使用詳解

    這篇文章主要介紹了Vue中slot的使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • 詳解axios全局路由攔截的設(shè)置方法

    詳解axios全局路由攔截的設(shè)置方法

    這篇文章主要介紹了axios全局路由攔截的設(shè)置方法,axios全局路由代碼通常是在構(gòu)建axios實(shí)例注入的,本文通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-09-09
  • 詳解在Vue中如何模塊化使用Vuex

    詳解在Vue中如何模塊化使用Vuex

    這篇文章給大家介紹了在Vue 中如何模塊化使用 Vuex,文中通過代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-01-01

最新評(píng)論