【前端】Vue项目:旅游App-(15)home:网络请求house数据、动态并组件化展示house列表信息

news2024/9/24 15:24:47

文章目录

    • 目标
    • 过程与代码
      • content组件
      • 请求数据:houseList
        • request
        • store
        • 控制台输出
      • 动态加载更多列表数据
      • house-item组件
        • 阶段1:数据传送
        • 阶段2:对着目标写样式
          • house-item-v9
          • house-item-v9:debug
          • house-item-v3
        • 阶段3:总体效果
    • 效果
    • 总代码
      • 修改或添加的文件
      • house-item
        • house-item-v9
        • house-item-v3
      • service的home.js
      • store的home.js
      • cpns的home-content
      • main.js
    • 参考

本项目博客总结:【前端】Vue项目:旅游App-博客总结

目标

完成热门精选的内容。

  • 数据来源:网络请求123.207.32.32:1888/api/home/houselist?page=1
  • 把它抽取成组件

在这里插入图片描述

过程与代码

content组件

我们将houseList的内容抽取到一个组件中,将其命名为home-content.vue。

<template>
    <div class="content">
        <h2>热门精选</h2>
        <div class="list">

        </div>
    </div>
</template>

<script setup>

</script>

<style lang="less" scoped>
.content {
    padding: 0 20px;
    h2 {
        font-size: 20px;
        font-weight: 700;
    }
}
</style>

请求数据:houseList

数据是分页的。

第1页:123.207.32.32:1888/api/home/houselist?page=1
第2页:123.207.32.32:1888/api/home/houselist?page=2
以此类推。

本项目已经多此实现对数据请求的功能,因此这里不再赘述。

数据输出:

在这里插入图片描述

request

get请求的参数为params,post请求的参数为data。

这里先写死:请求第一页数据。

export function getHouseList() {
    return HYRequest.get({
        url: '/home/houselist',
        params: {
            page: 1
        }
    })
}

store

// home.vue页面所有的进行网络请求和数据都封装到这里

import { defineStore } from "pinia";
import { getHotSuggest, getCategories, getHouseList } from '@/service'

const useHomeStore = defineStore('home', {
    state: () => {
        return {
            hotSuggest: [],
            categories: [],
            houseList: [],
        }
    },
    actions: {
        // 网络请求,由于返回一个promise,要异步async await
        async fetchHotSuggest() {
            const res = await getHotSuggest()
            this.hotSuggest = res.data
            // console.log(res)
        },
        async fetchCategories() {
            const res = await getCategories()
            this.categories = res.data
        },
        async fetchHouseList() {
            const res = await getHouseList()
            this.houseList = res.data
        }
    }
})

export default useHomeStore

控制台输出

数据请求成功。
在这里插入图片描述

动态加载更多列表数据

这里的数据一页只有20条,而我们也在代码中写死参数page=1。
实际上,App中此模块的数据是在下拉过程中加载更多的数据。因此我们要动态地加载数据。
这里要使用Array.push...解构语法。

为什么要解构?
答:网络请求得到的是一个数组,不解构会使store中的数据变成二维数组,这不是我们想要的。

如何动态地加载数据?
我们可以先用一个按钮模拟这个功能,每次点击按钮就加载更多的数据,page的参数可以用currentPage来表示,每点击按钮令currentPage++。currentPage存在store中。

request:

export function getHouseList(currentPage) {
    return HYRequest.get({
        url: '/home/houselist',
        params: {
            page: currentPage
        }
    })
}

store:

// home.vue页面所有的进行网络请求和数据都封装到这里

import { defineStore } from "pinia";
import { getHotSuggest, getCategories, getHouseList } from '@/service'

const useHomeStore = defineStore('home', {
    state: () => {
        return {
            hotSuggest: [],
            categories: [],
            houseList: [],
            currentPage: 1,

        }
    },
    actions: {
        // 网络请求,由于返回一个promise,要异步async await
        async fetchHotSuggest() {
            const res = await getHotSuggest()
            this.hotSuggest = res.data
            // console.log(res)
        },
        async fetchCategories() {
            const res = await getCategories()
            this.categories = res.data
        },
        async fetchHouseList() {
            const res = await getHouseList(this.currentPage)
            this.currentPage++
            this.houseList.push(...res.data)
        }
    }
})

export default useHomeStore

按钮:

<button @click="moreList()">page++</button>
function moreList(){
    homeStore.fetchHouseList()
}

初始状态:说明只请求了第一页数据。

在这里插入图片描述
点一次按钮:请求了第二页数据。
在这里插入图片描述
注意store中currentPage的代码。它表示的是下一次要请求的页面。

根据F12中的网络也可以得知请求的数据:

在这里插入图片描述

house-item组件

显然house-item可能会在项目中多个地方使用,因此我们要把它单独抽为对应组件:

在这里插入图片描述
注意,数据中discoveryContentType表示不同的展示列表数据的方式。上图左为9,右为3.

思路:

  • house-content判断discoveryContentType,为3则引入组件house-item-v3,为9则引入组件house-item-v9
  • house-item中定义props:item
  • house-content中传入数据house-item

阶段1:数据传送

数据的传送情况如下:

在这里插入图片描述
当前效果:

在这里插入图片描述
对应代码:

home-content:

<template>
    <div class="content">
        <h2>热门精选</h2>

        <div class="list">
            <template v-for="(item, index) in houseList" :key="item.data.houseId">
                <houseItemV9 v-if="item.discoveryContentType === 9" :item="item.data"></houseItemV9>
                <houseItemV3 v-else-if="item.discoveryContentType === 3" :item="item.data"></houseItemV3>
            </template>
        </div>
    </div>
</template>

<script setup>
import { storeToRefs } from "pinia";
import useHomeStore from "../../../store/modules/home";
import houseItemV9 from "../../../components/house-item/house-item-v9.vue";
import houseItemV3 from "../../../components/house-item/house-item-v3.vue";


const homeStore = useHomeStore()
homeStore.fetchHouseList()
const { houseList } = storeToRefs(homeStore)
console.log(houseList)

</script>

<style lang="less" scoped>
.content {
    padding: 0 20px;

    h2 {
        font-size: 20px;
        font-weight: 700;
    }
}
</style>

house-item-v9:

<template>
    <div class="house-item">
        <h2>v9 {{item.houseName}}</h2>
    </div>
</template>

<script setup>
defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})
</script>

<style lang="less" scoped>

</style>

house-item-v3:

<template>
    <div class="house-item">
        <h2>v3 {{item.houseName}}</h2>
    </div>
</template>

<script setup>
defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})
</script>

<style lang="less" scoped>

</style>

阶段2:对着目标写样式

评分使用vant库。Rate 评分 - Vant 4 (gitee.io)

要显示小数。

在这里插入图片描述

house-item-v9

效果:

在这里插入图片描述
代码:

<template>
    <div class="house-item">
        <div class="house-inner">
            <div class="image">
                <img :src="item.image.url" alt="">
            </div>
            <div class="info">
                <div class="summary">{{ item.summaryText }}</div>
                <div class="name">{{ item.houseName }}</div>
                <div class="tips">
                    <div class="stars" >
                        <van-rate v-model="starValue" readonly allow-half size="12px"/>
                    </div>
                    <div class="price">
                        ¥{{ item.finalPrice }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue';

const props = defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})

const starValue = ref(props.item.commentScore);
</script>

<style lang="less" scoped>
.house-item {
    // 每个item宽度占屏幕一半
    width: 50%;
    margin-top: 20px;

    .house-inner {
        // 信息在img上:子绝父相
        position: relative;

        margin: 5px;

        .image {
            img {
                width: 100%;
                border-radius: 6px;
            }
        }

        .info {
            position: absolute;
            bottom: 0;

            padding: 8px 10px;

            color: #fff;

            .summary {
                font-size: 12px;
            }

            .name {
                // 超过2行就省略号省略...
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;

                margin: 5px 0;
            }

            .tips{
                display: flex;
                justify-content: space-between;
            }
        }

    }
}
</style>
house-item-v9:debug

出现了一个问题:4.8分只有4颗星。

控制台报错:

在这里插入图片描述
大致意思:modelValue要的是Number而不是String。

查看Vue插件的starValue:是字符串。

在这里插入图片描述
因此我们要把它改成Number。

const starValue = ref(Number(props.item.commentScore));
house-item-v3

icon的引入:Icon 图标 - Vant 4 (gitee.io)

在这里插入图片描述
效果:

在这里插入图片描述
代码:

<template>
    <div class="house-item">
        <div class="house-inner">
            <div class="image">
                <img :src="item.image.url" alt="">
            </div>
            <div class="info">
                <div class="location">
                    <van-icon name="location" color="#808080" />
                    {{ item.location }}
                </div>
                <div class="name">{{ item.houseName }}</div>
                <div class="summary">{{ item.summaryText }}</div>
                <div class="price">
                    <div class="cheap">¥{{ item.finalPrice }}</div>
                    <div class="exp">{{ item.productPrice }}</div>
                    <div class="sale">立减¥{{ item.productPrice - item.finalPrice }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})
</script>

<style lang="less" scoped>
.house-item {
    width: 50%;

    .house-inner {
        margin: 5px;

        .image {
            img {
                width: 100%;
                border-radius: 6px;
            }
        }

        .info {
            padding: 15px 8px 0;

            .location {
                color: #000;
            }

            .name {
                color: #333;
                margin: 5px 0;

                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
            }

            .summary {
                color: #666;
                font-size: 12px;
            }

            .price {
                display: flex;
                justify-content: left;
                align-items: center;

                margin: 10px 0;

                .cheap {
                    color: var(--primary-color);
                }

                .exp {
                    color: #999;
                    text-decoration: line-through;
                    font-size: 12px;
                    margin: 0 5px;
                }

                .sale {
                    font-size: 12px;
                    color: #fff;
                    border-radius: 10px;
                    padding: 0 3px;
                    background-image: linear-gradient(270deg, #f66, #ff9f9f);
                }
            }
        }
    }
}
</style>

阶段3:总体效果

当前:

在这里插入图片描述
css改为:

.list{
        margin-top: 20px;
        display: flex;
        flex-wrap: wrap;
    }

效果:

在这里插入图片描述

效果

在这里插入图片描述

总代码

修改或添加的文件

在这里插入图片描述
在这里插入图片描述

house-item

展示house信息的列表,分为两种,标号分别为9和3.

house-item-v9

标号为9的展示house信息的组件。

<template>
    <div class="house-item">
        <div class="house-inner">
            <div class="image">
                <img :src="item.image.url" alt="">
            </div>
            <div class="info">
                <div class="summary">{{ item.summaryText }}</div>
                <div class="name">{{ item.houseName }}</div>
                <div class="tips">
                    <div class="stars" >
                        <van-rate v-model="starValue" readonly allow-half size="12px"/>
                    </div>
                    <div class="price">
                        ¥{{ item.finalPrice }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue';

const props = defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})

const starValue = ref(Number(props.item.commentScore));
</script>

<style lang="less" scoped>
.house-item {
    // 每个item宽度占屏幕一半
    width: 50%;

    .house-inner {
        // 信息在img上:子绝父相
        position: relative;

        margin: 5px;

        .image {
            img {
                width: 100%;
                border-radius: 6px;
            }
        }

        .info {
            position: absolute;
            bottom: 0;

            padding: 8px 10px;

            color: #fff;

            .summary {
                font-size: 12px;
            }

            .name {
                // 超过2行就省略号省略...
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;

                margin: 5px 0;
            }

            .tips{
                display: flex;
                justify-content: space-between;
            }
        }

    }
}
</style>

house-item-v3

标号为3的展示house信息的组件。

<template>
    <div class="house-item">
        <div class="house-inner">
            <div class="image">
                <img :src="item.image.url" alt="">
            </div>
            <div class="info">
                <div class="location">
                    <van-icon name="location" color="#808080" />
                    {{ item.location }}
                </div>
                <div class="name">{{ item.houseName }}</div>
                <div class="summary">{{ item.summaryText }}</div>
                <div class="price">
                    <div class="cheap">¥{{ item.finalPrice }}</div>
                    <div class="exp">{{ item.productPrice }}</div>
                    <div class="sale">立减¥{{ item.productPrice - item.finalPrice }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})
</script>

<style lang="less" scoped>
.house-item {
    width: 50%;

    .house-inner {
        margin: 5px;

        .image {
            img {
                width: 100%;
                border-radius: 6px;
            }
        }

        .info {
            padding: 15px 8px 0;

            .location {
                color: #000;
            }

            .name {
                color: #333;
                margin: 5px 0;

                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
            }

            .summary {
                color: #666;
                font-size: 12px;
            }

            .price {
                display: flex;
                justify-content: left;
                align-items: center;

                margin: 10px 0;

                .cheap {
                    color: var(--primary-color);
                }

                .exp {
                    color: #999;
                    text-decoration: line-through;
                    font-size: 12px;
                    margin: 0 5px;
                }

                .sale {
                    font-size: 12px;
                    color: #fff;
                    border-radius: 10px;
                    padding: 0 3px;
                    background-image: linear-gradient(270deg, #f66, #ff9f9f);
                }
            }
        }
    }
}
</style>

service的home.js

home页面网络请求数据的代码。

// 此文件保存所有home页面的网络请求
import HYRequest from '@/service/request'

export function getHotSuggest() {
    // request的index导出的是一个对象
    return HYRequest.get({
        // 参数也是一个对象
        url: '/home/hotSuggests'
    })
}

export function getCategories() {
    // request的index导出的是一个对象
    return HYRequest.get({
        // 参数也是一个对象
        url: '/home/categories'
    })
}

export function getHouseList(currentPage) {
    return HYRequest.get({
        url: '/home/houselist',
        params: {
            page: currentPage
        }
    })
}

store的home.js

管理home页面网络请求的数据的代码。

// home.vue页面所有的进行网络请求和数据都封装到这里

import { defineStore } from "pinia";
import { getHotSuggest, getCategories, getHouseList } from '@/service'

const useHomeStore = defineStore('home', {
    state: () => {
        return {
            hotSuggest: [],
            categories: [],
            houseList: [],
            currentPage: 1,

        }
    },
    actions: {
        // 网络请求,由于返回一个promise,要异步async await
        async fetchHotSuggest() {
            const res = await getHotSuggest()
            this.hotSuggest = res.data
            // console.log(res)
        },
        async fetchCategories() {
            const res = await getCategories()
            this.categories = res.data
        },
        async fetchHouseList() {
            const res = await getHouseList(this.currentPage)
            this.currentPage++
            this.houseList.push(...res.data)
        }
    }
})

export default useHomeStore

cpns的home-content

抽取了展示house信息的列表。

<template>
    <div class="content">
        <h2>热门精选</h2>

        <div class="list">
            <template v-for="(item, index) in houseList" :key="item.data.houseId">
                <houseItemV9 v-if="item.discoveryContentType === 9" :item="item.data"></houseItemV9>
                <houseItemV3 v-else-if="item.discoveryContentType === 3" :item="item.data"></houseItemV3>
            </template>
        </div>
    </div>
</template>

<script setup>
import { storeToRefs } from "pinia";
import useHomeStore from "../../../store/modules/home";
import houseItemV9 from "../../../components/house-item/house-item-v9.vue";
import houseItemV3 from "../../../components/house-item/house-item-v3.vue";


const homeStore = useHomeStore()
homeStore.fetchHouseList()
const { houseList } = storeToRefs(homeStore)
console.log(houseList)

</script>

<style lang="less" scoped>
.content {
    padding: 0 20px;

    h2 {
        font-size: 20px;
        font-weight: 700;
    }

    .list{
        margin-top: 20px;
        display: flex;
        flex-wrap: wrap;
    }
}
</style>

main.js

引入了vant的Rate和Icon。

参考

HTML文字超过两行以后 就用省略号显示代替 - 简书 (jianshu.com)

/*超过2行就省略*/
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/187750.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Android ANR触发机制(二)

上一篇文章看了Service的ANR触发流程&#xff0c;现在看一下其他三种ANR触发流程。 1.BroadcastReceiver触发ANR BroadcastReceiver超时是位于ActivityManager线程中的BroadcastQueue.BroadcastHandler收到BROADCAST_TIMEOUT_MSG消息时触发。 广播队列分为foreground队列和b…

基于Java+SpringBoot+Vue前后端分离学生管理系统设计与实现

博主介绍&#xff1a;✌全网粉丝3W&#xff0c;全栈开发工程师&#xff0c;从事多年软件开发&#xff0c;在大厂呆过。持有软件中级、六级等证书。可提供微服务项目搭建与毕业项目实战✌ 博主作品&#xff1a;《微服务实战》专栏是本人的实战经验总结&#xff0c;《Spring家族及…

2023年二月份图形化二级打卡试题

活动时间 从2023年 2月1日至1月21日&#xff0c;每天一道编程题。 本次打卡的规则如下&#xff1a; &#xff08;1&#xff09;小朋友每天利用10~15分钟做一道编程题&#xff0c;遇到问题就来群内讨论&#xff0c;我来给大家答疑。 &#xff08;2&#xff09;小朋友做完题目后&…

数组中和为0的三个数

给你一个整数数组 nums &#xff0c;判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i ! j、i ! k 且 j ! k &#xff0c;同时还满足 nums[i] nums[j] nums[k] 0 。请你返回所有和为 0 且不重复的三元组。 注意: 答案中不可以包含重复的三元组。 示例 1: 输入: num…

了解SLI、SLO和SLA

了解SLI、SLO和SLA 概念解释 服务水平指标(SLI) SLI代表目前服务的状态&#xff0c;例如可以是最基本的接口成功率、p99响应时间&#xff0c;也可以是一些业务指标&#xff0c;例如用户投诉率之类的。是可量化&#xff0c;是可确定的。 服务水平目标(SLO) SLO是目标&#x…

【树】哈夫曼树和哈夫曼编码

哈夫曼&#xff08;Huffman&#xff09;树&#xff0c;又称最优树&#xff0c;是一类带权路径长度最短的树。最优二叉树&#xff08;哈夫曼树&#xff09;路径&#xff1a;从树中一个结点到另一个结点之间的分支构成这两个结点之间的路。路径长度:路径上的分支数目&#xff1b;…

mysql分组排序取组内第一的数据行获取分组后,组内排名第一或最后的数据行。

前言&#xff1a; group by函数后取到的是分组中的第一条数据&#xff0c;但是我们有时候需要取出各分组的最新一条&#xff0c;该怎么实现呢&#xff1f; 本文提供两种实现方式。 一、准备数据 DROP TABLE IF EXISTS tb_dept; CREATE TABLE tb_dept (id bigint(20) UNSIG…

chat聊天系统消息消费时遇到的问题及优化思路

前言 之前有段工作经历涉及到了chat相关&#xff0c;而消息的发送 -> 存储 -> 消费是由不同的团队负责的&#xff0c;因此消息如何再多个团队之间流通、以及通过什么介质传递都是需要考虑的问题。 之前我负责过一些消息消费的相关工作&#xff0c;消息发送团队将消息推…

【Linux】简介磁盘|inode|动静态库

目录一.简介磁盘1.磁盘的物理结构&#xff1a;2.磁盘存储方式&#xff1a;3.磁盘的逻辑抽象&#xff1a;二.inode&&文件系统1.inode文件属性&#xff08;inode&#xff09;内容&#xff08;data block&#xff09;为什么删除一个文件相比于写一个文件要快得多&#xff…

若依配置教程(二)集成积木报表JimuReport

积木报表配置官网 在搭建好若依环境成功运行以后&#xff0c;我们先在这个系统中加一个小功能&#xff1a;JimuReport积木报表&#xff0c;以下步骤&#xff0c;我们按照官网教程&#xff0c;详细配置一下&#xff1a; 1.在ruoyi-admin文件夹下的pom.xml加入jar包依赖&#x…

MLP多层感知机理解

目录 .1简介 .2例子 2.1模型 2.2 实例 2.2.1 问题描述 2.2.2 数学过程 .3 代码 3.1 问题描述 3.2 代码 references&#xff1a; .1简介 多层感知机是全连接的 可以把低维的向量映射到高维度 MLP整个模型就是这样子的&#xff0c;上面说的这个三层的MLP用公式总结起来…

C 语言零基础入门教程(二十)

C 预处理器 C 预处理器不是编译器的组成部分&#xff0c;但是它是编译过程中一个单独的步骤。简言之&#xff0c;C 预处理器只不过是一个文本替换工具而已&#xff0c;它们会指示编译器在实际编译之前完成所需的预处理。我们将把 C 预处理器&#xff08;C Preprocessor&#x…

练手好福利!20个Python实战项目含源代码【2023最新】

高效学习源代码的步骤&#xff1a;1.运行程序&#xff0c;观察表现2.运行源码&#xff0c;断点调试&#xff0c;从头跟一边源码的执行流程&#xff0c;注意函数堆栈3.画类图、流程图&#xff0c;先把遇到的重要类记录下来&#xff0c;表明各个类的关系4.记录问题&#xff0c;把…

Unity XR

一、几个Unity XR Interaction Toolkit学习地址 1.B站视频 https://www.bilibili.com/video/BV11q4y1b74z/?spm_id_from333.999.0.0&vd_source8125d294022d2e63a58dfd228a7fcf63 https://www.bilibili.com/video/BV13b4y177J4/?spm_id_from333.999.0.0&vd_source8…

【对象的比较】java代码实现,详解对象的比较,Comparable接口和Comparator比较器

前言&#xff1a; 大家好&#xff0c;我是良辰丫&#xff0c;&#x1f49e;&#x1f49e;&#x1f49e;今天的我们要学习的知识点是java对象的比较&#xff0c;不是大家现实生活中对象的比较&#xff0c;是java中new一个对象的那个对象&#xff0c;对象的比较到底是什么意思呢&…

24.网络编程(二)

目录 三.TCP通信 3.1 TCP协议特点 3.2 TCP协议通信场景 3.3 TCP通信模型演示 3.4 Socket 3.5 ServerSocket 3.6 注意事项 3.7 案例 3.7.1 TCP通信—单发单收 3.7.2 TCP通信—多发多收 3.7.3 TCP通信—同时接收多个客户端的消息。 3.7.4 TCP通信—使用线程池优化&am…

工业相机和镜头

工业相机和镜头镜头型号数据电源接口定焦镜头的调焦景深景深大小光圈相机、镜头选取参考镜头型号、数据电源接口、定焦镜头的调焦、景深、景深大小、光圈、相机、镜头选取 镜头型号 C&#xff0c;CS系列&#xff1a;相机镜头的C、CS接口非常相似&#xff0c;它们的接口直径、螺…

检索业务:基本数据渲染和排错

采用标签显示商品的数据 <div class"rig_tab"><div th:each"product:${result.getProducts()}"><div class"ico"><i class"iconfont icon-weiguanzhu"></i><a href"/static/search/#">…

5、数据的重构

目录 一、为什么进行数据重构 二、如何进行数据重构 一、为什么进行数据重构 进行数据分析时&#xff0c;有可能会发现数据的结构并不适合直接进行数据分析操作&#xff0c;如下面数据&#xff0c;但通过复制-粘贴-转置等方法操作又太繁琐&#xff0c;数据量小还行&#xff…

C++ 图进阶系列之 kruskal 和 Prim 算法_图向最小生成树的华丽转身

1. 前言 树和图形状相似&#xff0c;也有差异性。树中添加一条或多条边&#xff0c;可成图。图中减小一条或多条边&#xff0c;可成树。形态的变化由数据之间的逻辑关系决定。 图用来描述数据之间多对多关系。树用来描述数据之间一对多关系。 思考如下问题&#xff1f; 如果…