最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue開(kāi)發(fā)實(shí)現(xiàn)評(píng)論列表

 更新時(shí)間:2022年04月14日 17:02:15   作者:qq_35758831  
這篇文章主要為大家詳細(xì)介紹了vue開(kāi)發(fā)實(shí)現(xiàn)評(píng)論列表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue開(kāi)發(fā)實(shí)現(xiàn)評(píng)論列表的具體代碼,供大家參考,具體內(nèi)容如下

index.html

<!DOCTYPE html>
<html>
? <head>
? ? <meta charset="utf-8">
? ? <meta name="viewport" content="width=device-width,initial-scale=1.0">
?? ?<link rel="stylesheet" href="./static/css/bootstrap.css">
? ? <title>y</title>
? </head>
? <body>
? ? <div id="app"></div>
? ? <!-- built files will be auto injected -->
? </body>
</html>

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
? el: '#app',
? components: { App },
? template: '<App/>',
})

App.vue

<template>
? <div id="app">
? ? <header class="site-header jumbotron">
? ? ? <div class="container">
? ? ? ? <div class="row">
? ? ? ? ? <div class="col-xs-12">
? ? ? ? ? ? <h1>請(qǐng)發(fā)表對(duì)vue的評(píng)論</h1>
? ? ? ? ? </div>
? ? ? ? </div>
? ? ? </div>
? ? </header>

? ? <div class="container">
? ? ? <Add :addComment="addComment"/>
? ? ? <List :comments="comments" :deleteComment="deleteComment"/>
? ? </div>
? </div>
</template>

<script>
? import Add from './components/Add.vue'
? import List from './components/List.vue'

? export default {

? ? data() {
? ? ? return { ?//數(shù)據(jù)在哪個(gè)組件,更新數(shù)據(jù)的行為就在哪個(gè)組件
? ? ? ? comments: [{
? ? ? ? ? ? name: 'BoB',
? ? ? ? ? ? content: 'Vue還不錯(cuò)'
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? name: 'Cat',
? ? ? ? ? ? content: 'Vue so easy'
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? name: 'Xhong',
? ? ? ? ? ? content: 'Vue so so'
? ? ? ? ? }
? ? ? ? ]
? ? ? }
? ? },

? ? methods: {
? ? ? //添加評(píng)論
? ? ? addComment(comment){
? ? ? ? this.comments.unshift(comment)
? ? ? },
? ? ? //刪除指定的評(píng)論
? ? ? deleteComment(index){
? ? ? ? this.comments.splice(index,1)
? ? ? }
? ? },

? ? components: {
? ? ? Add,
? ? ? List
? ? }
? }
</script>

<style>

</style>

Add.vue

<template>
? <div class="col-md-4">
? ? <form class="form-horizontal">
? ? ? <div class="form-group">
? ? ? ? <lable>用戶名</lable>
? ? ? ? <input type="text" class="form-control" placeholder="用戶名" v-model="name">
? ? ? </div>
? ? ? <div class="form-group">
? ? ? ? <lable>評(píng)論內(nèi)容</lable>
? ? ? ? <textarea class="form-control" cols="30" rows="6" placeholder="評(píng)論內(nèi)容" v-model="content"></textarea>
? ? ? </div>
? ? ? <div class="form-group">
? ? ? ? <div class="col-sm-offset-2 col-sm-10">
? ? ? ? ? <button type="button" class="btn btn-default pull-right" @click="add">提交</button>
? ? ? ? </div>
? ? ? </div>
? ? </form>
? </div>
</template>

<script>
? export default {
? ? props: {
? ? ? addComment: {
? ? ? ? type:Function,
? ? ? ? required:true
? ? ? }
? ? },
? ? data() {
? ? ? return {
? ? ? ? name: '',
? ? ? ? content: ''
? ? ? }
? ? },
? ? methods: {
? ? ? add() {
? ? ? ? ? //檢查輸入的合法性
? ? ? ? ? const name=this.name.trim();
? ? ? ? ? const content=this.content.trim();
? ? ? ? ? if(!name || !content){
? ? ? ? ? ? alert('姓名或內(nèi)容不能為空')
? ? ? ? ? ? return
? ? ? ? ? }

? ? ? ? ?//根據(jù)輸入的數(shù)據(jù)封裝成一個(gè)對(duì)象
? ? ? ? ? const comment = {
? ? ? ? ? ? name,
? ? ? ? ? ? content
? ? ? ? ? }
? ? ? ? ? //添加到comments中
? ? ? ? ? this.addComment(comment)

? ? ? ? ? //清除數(shù)據(jù)
? ? ? ? ? this.name = ''
? ? ? ? ? this.content = ''

? ? ? }
? ? }
? }
</script>

<style>
</style>

List.vue

<template>
? <div class="col-md-8">
? ? <h3 class="reply">評(píng)論回復(fù):</h3>
? ? <h2 v-show="comments.length===0">暫無(wú)評(píng)論,點(diǎn)擊左側(cè)添加評(píng)論?。。?lt;/h2>
? ? <ul class="list-group">
? ? ? <Item v-for="(comment, index) in comments" :key="index" :comment="comment" :deleteComment="deleteComment" :index="index"/>
? ? </ul>
? </div>
</template>

<script>
? import Item from './Item.vue'

? export default {
? ? //聲明接受屬性,這個(gè)屬性就會(huì)成為組件對(duì)象的屬性
? ? props:['comments','deleteComment'],

? ? components:{
? ? ? Item
? ? }
? }
</script>

<style>
? .reply {
? ? margin-top: 0px;
? }
</style>

Item.vue

<template>
? <li class="list-group-item">
? ? <div class="handle">
? ? ? <a href="javascript:;" @click="deleteItem">刪除</a>
? ? </div>
? ? <p class="user"><span>{{comment.name}}</span><span>說(shuō):</span></p>
? ? <p class="centence">{{comment.content}}</p>
? </li>
</template>

<script>

? export default {
? ? props: { //指定屬性名和屬性值得類型
? ? ? comment: Object,
? ? ? deleteComment: Function,
? ? ? index: Number
? ? },

? ? methods: {
? ? ? deleteItem() {
? ? ? ? const {comment,deleteComment,index}=this
? ? ? ? if(window.confirm(`確定刪除${comment.name}的評(píng)論嗎?`)){
? ? ? ? ? deleteComment(index)
? ? ? ? }
? ? ? }
? ? }
? }

</script>

<style>
? li {
? ? transition: .5s;
? ? overflow: hidden;
? }

? .handle {
? ? width: 40px;
? ? border: 1px solid #CCCCCC;
? ? background: #FFFFFF;
? ? position: absolute;
? ? right: 10px;
? ? top: 1px;
? ? text-align: center;
? }
? .handle a {
? ? display: block;
? ? text-decoration: none;
? }
? .list-group-item .centence {
? ? padding: 0px 50px;
? }

? .user {
? ? font-size: 22px;
? }
</style>

目錄結(jié)構(gòu)

最終效果

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

相關(guān)文章

  • Ant?Design?of?Vue的樹(shù)形控件Tree的使用及說(shuō)明

    Ant?Design?of?Vue的樹(shù)形控件Tree的使用及說(shuō)明

    這篇文章主要介紹了Ant?Design?of?Vue的樹(shù)形控件Tree的使用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vue3中操作dom的四種方式總結(jié)(建議收藏!)

    Vue3中操作dom的四種方式總結(jié)(建議收藏!)

    VUE是通過(guò)傳遞一些配置給Vue對(duì)象和頁(yè)面中引用插值表達(dá)式來(lái)操作DOM的,下面這篇文章主要給大家介紹了關(guān)于Vue3中操作dom的四種方式總結(jié),文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • 淺談Vue.use的使用

    淺談Vue.use的使用

    這篇文章主要介紹了淺談Vue.use的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • vue.js內(nèi)置組件之keep-alive組件使用

    vue.js內(nèi)置組件之keep-alive組件使用

    keep-alive是Vue.js的一個(gè)內(nèi)置組件。這篇文章主要介紹了vue.js內(nèi)置組件之keep-alive組件使用,需要的朋友可以參考下
    2018-07-07
  • vue3中使用百度地圖的簡(jiǎn)單步驟

    vue3中使用百度地圖的簡(jiǎn)單步驟

    最近項(xiàng)目要用到百度地圖api,好久沒(méi)用到地圖,就百度了一番,下面這篇文章主要給大家介紹了關(guān)于vue3中使用百度地圖的簡(jiǎn)單步驟,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • Vue使用distpicker插件實(shí)現(xiàn)省市級(jí)下拉框三級(jí)聯(lián)動(dòng)

    Vue使用distpicker插件實(shí)現(xiàn)省市級(jí)下拉框三級(jí)聯(lián)動(dòng)

    這篇文章主要介紹了Vue使用distpicker插件實(shí)現(xiàn)省市級(jí)下拉框三級(jí)聯(lián)動(dòng),比如通過(guò)JSON文件生成對(duì)應(yīng)的區(qū)域下拉框,element-china-are插件,包括distpicker插件,通過(guò)代碼講解如何使用distpicker插件實(shí)現(xiàn)省市級(jí)三聯(lián)跳動(dòng),需要的朋友可以參考下
    2023-02-02
  • Vue實(shí)現(xiàn)骨架屏的示例代碼

    Vue實(shí)現(xiàn)骨架屏的示例代碼

    骨架屏就是在頁(yè)面數(shù)據(jù)尚未加載前先給用戶展示出頁(yè)面的大致結(jié)構(gòu)。本文將利用Vue實(shí)現(xiàn)簡(jiǎn)單的骨架屏,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-03-03
  • vue中如何使用xlsx讀取excel文件實(shí)例代碼

    vue中如何使用xlsx讀取excel文件實(shí)例代碼

    在Vue中使用xlsx庫(kù)可以幫助我們讀取和寫入Excel文件,下面這篇文章主要給大家介紹了關(guān)于vue中如何使用xlsx讀取excel文件的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • 使用Nuxt.js改造已有項(xiàng)目的方法

    使用Nuxt.js改造已有項(xiàng)目的方法

    這篇文章主要介紹了使用Nuxt.js改造已有項(xiàng)目的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Vue引入jQuery的方法和配置教程

    Vue引入jQuery的方法和配置教程

    雖然Vue.js作為一個(gè)現(xiàn)代化的前端框架,鼓勵(lì)使用其自身的響應(yīng)式機(jī)制來(lái)處理DOM操作,但在某些情況下,尤其是在需要維護(hù)舊系統(tǒng)的項(xiàng)目中,可能會(huì)遇到需要引入jQuery的情況,本文將詳細(xì)講解如何在Vue項(xiàng)目中引入jQuery,需要的朋友可以參考下
    2024-09-09

最新評(píng)論

嘉禾县| 奉化市| 麟游县| 纳雍县| 读书| 灵宝市| 英山县| 临澧县| 连江县| 阜平县| 嘉鱼县| 视频| 阳新县| 东城区| 咸丰县| 辽中县| 古浪县| 诏安县| 凤冈县| 鲁山县| 柯坪县| 崇仁县| 甘德县| 漳浦县| 金阳县| 西城区| 庆元县| 临高县| 泽州县| 昔阳县| 诏安县| 义马市| 电白县| 广水市| 尉氏县| 南丹县| 石渠县| 廉江市| 湛江市| 安达市| 张家口市|