Vue購物車應用實現教程

文章目錄

    • 1. 項目介紹
    • 2. 開發環境準備
    • 3. 設計購物車界面
    • 4. 創建Vue實例和數據模型
    • 5. 實現購物車功能
      • 5.1 從本地存儲加載數據
      • 5.2 監聽數據變化保存到本地存儲
      • 5.3 實現全選/反選功能
      • 5.4 計算選中商品的總價和總數量
      • 5.5 實現修改商品數量功能
      • 5.6 實現刪除商品功能
      • 5.7 實現結算功能
    • 6. 添加樣式
    • 7. 完整代碼
    • 8. Vue知識點解析
      • 8.1 數據渲染與綁定
      • 8.2 條件渲染與列表渲染
      • 8.3 類與樣式綁定
      • 8.4 事件處理
      • 8.5 計算屬性
      • 8.6 偵聽器
      • 8.7 生命周期鉤子
      • 8.8 屬性綁定
    • 9. 功能擴展思路
    • 10. 總結

1. 項目介紹

本教程將帶領初學者開發一個基于Vue.js的購物車應用,不需要使用腳手架,僅通過引入Vue.js庫即可完成。通過這個項目,你將學習Vue的基礎知識,包括:

  • 數據渲染與綁定
  • 事件處理
  • 計算屬性
  • 偵聽器
  • 條件渲染與列表渲染
  • 本地存儲

完成后的購物車應用具有以下功能:

  • 商品列表渲染
  • 刪除商品
  • 修改商品數量
  • 全選/反選功能
  • 統計選中商品的總價和總數量
  • 數據持久化到本地存儲

2. 開發環境準備

對于初學者,我們采用最簡單的方式搭建環境:通過CDN引入Vue.js。

創建一個基本的HTML文件結構:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Vue購物車</title><!-- 引入Vue.js --><script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script><!-- 添加一些基本樣式 --><style>/* 樣式稍后添加 */</style>
</head>
<body><div id="app"><!-- 這里將是我們的應用 --></div><script>// Vue代碼將寫在這里</script>
</body>
</html>

3. 設計購物車界面

我們設計一個簡潔的購物車界面,包含以下部分:

  1. 標題
  2. 商品列表(每項包含復選框、圖片、名稱、單價、數量控制和刪除按鈕)
  3. 底部結算欄(全選按鈕、總計和結算按鈕)

更新HTML結構:

<div id="app"><div class="cart"><div class="cart-header"><h1>{{ title }}</h1></div><!-- 購物車為空時顯示 --><div class="empty-cart" v-if="cartItems.length === 0"><p>購物車空空如也,快去選購商品吧!</p></div><!-- 購物車商品列表 --><div class="cart-items" v-else><div class="cart-item" v-for="(item, index) in cartItems" :key="item.id" :class="{'selected-item': item.checked}"><div class="item-check"><input type="checkbox" v-model="item.checked"></div><div class="item-img"><img :src="item.img" :alt="item.name"></div><div class="item-info"><h3>{{ item.name }}</h3><p class="item-price">¥{{ item.price.toFixed(2) }}</p></div><div class="item-quantity"><button @click="decreaseQuantity(item.id)" :disabled="item.quantity <= 1">-</button><input type="number" v-model.number="item.quantity" min="1"><button @click="increaseQuantity(item.id)">+</button></div><div class="item-subtotal"><p>¥{{ (item.price * item.quantity).toFixed(2) }}</p></div><div class="item-remove"><button @click="removeItem(item.id)">刪除</button></div></div></div><!-- 購物車底部結算欄 --><div class="cart-footer" v-if="cartItems.length > 0"><div class="select-all"><input type="checkbox" v-model="selectAll"><label>全選</label></div><div class="cart-total"><p>已選擇 <span>{{ selectedCount }}</span> 件商品</p><p>總計: <span>¥{{ totalPrice }}</span></p></div><div class="checkout"><button @click="checkout">結算</button></div></div></div>
</div>

4. 創建Vue實例和數據模型

在script標簽中,我們創建Vue實例并定義數據模型:

new Vue({el: '#app',data: {title: 'Vue購物車',// 購物車商品數據cartItems: [{id: 1,name: '商品1',price: 199,quantity: 1,img: 'https://via.placeholder.com/80',checked: false},{id: 2,name: '商品2',price: 299,quantity: 2,img: 'https://via.placeholder.com/80',checked: false},{id: 3,name: '商品3',price: 399,quantity: 1,img: 'https://via.placeholder.com/80',checked: false}]},// 計算屬性將在后面定義computed: {// 計算屬性將在這里實現},// 方法將在后面定義methods: {// 方法將在這里實現},// 監聽器將在后面定義watch: {// 監聽器將在這里實現},// 生命周期鉤子函數將在后面定義created() {// 從本地存儲加載購物車數據}
});

5. 實現購物車功能

5.1 從本地存儲加載數據

首先,我們修改生命周期鉤子函數,從本地存儲加載購物車數據:

created() {// 從本地存儲加載購物車數據const savedCart = localStorage.getItem('vue-cart');if (savedCart) {this.cartItems = JSON.parse(savedCart);}
}

5.2 監聽數據變化保存到本地存儲

添加偵聽器,將購物車數據保存到本地存儲:

watch: {// 深度監聽購物車數據變化cartItems: {handler(newValue) {// 將購物車數據保存到本地存儲localStorage.setItem('vue-cart', JSON.stringify(newValue));},deep: true // 深度監聽對象內部的變化}
}

5.3 實現全選/反選功能

添加計算屬性和相關方法來實現全選/反選功能:

computed: {// 計算全選狀態selectAll: {// 獲取全選狀態get() {// 如果購物車為空,返回falseif (this.cartItems.length === 0) return false;// 檢查是否所有商品都被選中return this.cartItems.every(item => item.checked);},// 設置全選狀態set(value) {// 將所有商品的選中狀態設置為全選的狀態this.cartItems.forEach(item => {item.checked = value;});}}
}

5.4 計算選中商品的總價和總數量

添加計算屬性來統計選中商品的總價和總數量:

computed: {// 已定義的計算屬性selectAll: {// ... 前面的代碼},// 計算選中商品的總數量selectedCount() {return this.cartItems.reduce((total, item) => {return item.checked ? total + item.quantity : total;}, 0);},// 計算選中商品的總價totalPrice() {return this.cartItems.reduce((total, item) => {return item.checked ? total + (item.price * item.quantity) : total;}, 0).toFixed(2);}
}

5.5 實現修改商品數量功能

添加方法來增加和減少商品數量:

methods: {// 增加商品數量increaseQuantity(id) {const item = this.cartItems.find(item => item.id === id);if (item) {item.quantity++;}},// 減少商品數量decreaseQuantity(id) {const item = this.cartItems.find(item => item.id === id);if (item && item.quantity > 1) {item.quantity--;}}
}

5.6 實現刪除商品功能

添加方法來刪除購物車中的商品:

methods: {// 已定義的方法increaseQuantity(id) {// ... 前面的代碼},decreaseQuantity(id) {// ... 前面的代碼},// 刪除商品removeItem(id) {if (confirm('確定要刪除這個商品嗎?')) {// 根據id查找商品索引const index = this.cartItems.findIndex(item => item.id === id);if (index !== -1) {// 從數組中刪除商品this.cartItems.splice(index, 1);}}}
}

5.7 實現結算功能

添加一個簡單的結算方法:

methods: {// 已定義的方法// ... 前面的代碼// 結算方法checkout() {// 檢查是否有選中的商品if (this.selectedCount === 0) {alert('請至少選擇一件商品');return;}// 顯示結算信息alert(`您已選擇${this.selectedCount}件商品,總計:¥${this.totalPrice},感謝購買!`);// 實際應用中這里應該跳轉到結算頁面或發送請求到后端// 為了演示,我們僅移除已選中的商品this.cartItems = this.cartItems.filter(item => !item.checked);}
}

6. 添加樣式

為了讓購物車看起來更美觀,我們添加一些CSS樣式:

/* 將這些樣式添加到<style>標簽中 */
* {margin: 0;padding: 0;box-sizing: border-box;
}body {font-family: 'Microsoft YaHei', sans-serif;background-color: #f5f5f5;padding: 20px;
}.cart {max-width: 1000px;margin: 0 auto;background-color: white;border-radius: 8px;box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);overflow: hidden;
}.cart-header {padding: 20px;background-color: #f8f8f8;border-bottom: 1px solid #eee;
}.cart-header h1 {font-size: 24px;color: #333;text-align: center;
}.empty-cart {padding: 50px 20px;text-align: center;color: #999;
}.cart-items {padding: 0 20px;
}.cart-item {display: flex;align-items: center;padding: 20px 0;border-bottom: 1px solid #eee;
}.cart-item:last-child {border-bottom: none;
}.selected-item {background-color: rgba(135, 206, 250, 0.1);
}.item-check {width: 30px;
}.item-check input {width: 18px;height: 18px;
}.item-img {width: 80px;height: 80px;margin: 0 20px;
}.item-img img {width: 100%;height: 100%;object-fit: cover;border-radius: 4px;
}.item-info {flex: 1;padding-right: 20px;
}.item-info h3 {font-size: 16px;margin-bottom: 5px;color: #333;
}.item-price {color: #ff6700;font-weight: bold;
}.item-quantity {display: flex;align-items: center;margin: 0 20px;
}.item-quantity button {width: 30px;height: 30px;border: 1px solid #ddd;background-color: white;font-size: 16px;cursor: pointer;
}.item-quantity button:disabled {color: #ddd;cursor: not-allowed;
}.item-quantity input {width: 50px;height: 30px;border: 1px solid #ddd;border-left: none;border-right: none;text-align: center;font-size: 14px;
}.item-subtotal {width: 100px;text-align: right;font-weight: bold;color: #ff6700;
}.item-remove {width: 60px;text-align: center;
}.item-remove button {padding: 5px 10px;background-color: #ff6700;color: white;border: none;border-radius: 4px;cursor: pointer;
}.cart-footer {display: flex;justify-content: space-between;align-items: center;padding: 20px;background-color: #f8f8f8;border-top: 1px solid #eee;
}.select-all {display: flex;align-items: center;
}.select-all input {width: 18px;height: 18px;margin-right: 5px;
}.cart-total {flex: 1;text-align: right;padding-right: 20px;
}.cart-total p {margin-bottom: 5px;
}.cart-total span {color: #ff6700;font-weight: bold;font-size: 18px;
}.checkout button {padding: 10px 30px;background-color: #ff6700;color: white;border: none;border-radius: 4px;font-size: 16px;cursor: pointer;
}.checkout button:hover {background-color: #f25600;
}button:hover {opacity: 0.9;
}button:active {opacity: 0.8;
}/* 響應式布局 */
@media (max-width: 768px) {.cart-item {flex-wrap: wrap;}.item-info {width: 100%;padding: 10px 0;}.item-quantity, .item-subtotal, .item-remove {margin-top: 10px;}
}

7. 完整代碼

以下是完整的HTML文件代碼:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Vue購物車</title><script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script><style>* {margin: 0;padding: 0;box-sizing: border-box;}body {font-family: 'Microsoft YaHei', sans-serif;background-color: #f5f5f5;padding: 20px;}.cart {max-width: 1000px;margin: 0 auto;background-color: white;border-radius: 8px;box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);overflow: hidden;}.cart-header {padding: 20px;background-color: #f8f8f8;border-bottom: 1px solid #eee;}.cart-header h1 {font-size: 24px;color: #333;text-align: center;}.empty-cart {padding: 50px 20px;text-align: center;color: #999;}.cart-items {padding: 0 20px;}.cart-item {display: flex;align-items: center;padding: 20px 0;border-bottom: 1px solid #eee;}.cart-item:last-child {border-bottom: none;}.selected-item {background-color: rgba(135, 206, 250, 0.1);}.item-check {width: 30px;}.item-check input {width: 18px;height: 18px;}.item-img {width: 80px;height: 80px;margin: 0 20px;}.item-img img {width: 100%;height: 100%;object-fit: cover;border-radius: 4px;}.item-info {flex: 1;padding-right: 20px;}.item-info h3 {font-size: 16px;margin-bottom: 5px;color: #333;}.item-price {color: #ff6700;font-weight: bold;}.item-quantity {display: flex;align-items: center;margin: 0 20px;}.item-quantity button {width: 30px;height: 30px;border: 1px solid #ddd;background-color: white;font-size: 16px;cursor: pointer;}.item-quantity button:disabled {color: #ddd;cursor: not-allowed;}.item-quantity input {width: 50px;height: 30px;border: 1px solid #ddd;border-left: none;border-right: none;text-align: center;font-size: 14px;}.item-subtotal {width: 100px;text-align: right;font-weight: bold;color: #ff6700;}.item-remove {width: 60px;text-align: center;}.item-remove button {padding: 5px 10px;background-color: #ff6700;color: white;border: none;border-radius: 4px;cursor: pointer;}.cart-footer {display: flex;justify-content: space-between;align-items: center;padding: 20px;background-color: #f8f8f8;border-top: 1px solid #eee;}.select-all {display: flex;align-items: center;}.select-all input {width: 18px;height: 18px;margin-right: 5px;}.cart-total {flex: 1;text-align: right;padding-right: 20px;}.cart-total p {margin-bottom: 5px;}.cart-total span {color: #ff6700;font-weight: bold;font-size: 18px;}.checkout button {padding: 10px 30px;background-color: #ff6700;color: white;border: none;border-radius: 4px;font-size: 16px;cursor: pointer;}.checkout button:hover {background-color: #f25600;}button:hover {opacity: 0.9;}button:active {opacity: 0.8;}/* 響應式布局 */@media (max-width: 768px) {.cart-item {flex-wrap: wrap;}.item-info {width: 100%;padding: 10px 0;}.item-quantity, .item-subtotal, .item-remove {margin-top: 10px;}}</style>
</head>
<body><div id="app"><div class="cart"><div class="cart-header"><h1>{{ title }}</h1></div><!-- 購物車為空時顯示 --><div class="empty-cart" v-if="cartItems.length === 0"><p>購物車空空如也,快去選購商品吧!</p></div><!-- 購物車商品列表 --><div class="cart-items" v-else><div class="cart-item" v-for="(item, index) in cartItems" :key="item.id" :class="{'selected-item': item.checked}"><div class="item-check"><input type="checkbox" v-model="item.checked"></div><div class="item-img"><img :src="item.img" :alt="item.name"></div><div class="item-info"><h3>{{ item.name }}</h3><p class="item-price">¥{{ item.price.toFixed(2) }}</p></div><div class="item-quantity"><button @click="decreaseQuantity(item.id)" :disabled="item.quantity <= 1">-</button><input type="number" v-model.number="item.quantity" min="1"><button @click="increaseQuantity(item.id)">+</button></div><div class="item-subtotal"><p>¥{{ (item.price * item.quantity).toFixed(2) }}</p></div><div class="item-remove"><button @click="removeItem(item.id)">刪除</button></div></div></div><!-- 購物車底部結算欄 --><div class="cart-footer" v-if="cartItems.length > 0"><div class="select-all"><input type="checkbox" v-model="selectAll"><label>全選</label></div><div class="cart-total"><p>已選擇 <span>{{ selectedCount }}</span> 件商品</p><p>總計: <span>¥{{ totalPrice }}</span></p></div><div class="checkout"><button @click="checkout">結算</button></div></div></div></div><script>new Vue({el: '#app',data: {title: 'Vue購物車',// 購物車商品數據cartItems: [{id: 1,name: '商品1',price: 199,quantity: 1,img: 'https://via.placeholder.com/80',checked: false},{id: 2,name: '商品2',price: 299,quantity: 2,img: 'https://via.placeholder.com/80',checked: false},{id: 3,name: '商品3',price: 399,quantity: 1,img: 'https://via.placeholder.com/80',checked: false}]},computed: {// 計算全選狀態selectAll: {// 獲取全選狀態get() {// 如果購物車為空,返回falseif (this.cartItems.length === 0) return false;// 檢查是否所有商品都被選中return this.cartItems.every(item => item.checked);},// 設置全選狀態set(value) {// 將所有商品的選中狀態設置為全選的狀態this.cartItems.forEach(item => {item.checked = value;});}},// 計算選中商品的總數量selectedCount() {return this.cartItems.reduce((total, item) => {return item.checked ? total + item.quantity : total;}, 0);},// 計算選中商品的總價totalPrice() {return this.cartItems.reduce((total, item) => {return item.checked ? total + (item.price * item.quantity) : total;}, 0).toFixed(2);}},methods: {// 增加商品數量increaseQuantity(id) {const item = this.cartItems.find(item => item.id === id);if (item) {item.quantity++;}},// 減少商品數量decreaseQuantity(id) {const item = this.cartItems.find(item => item.id === id);if (item && item.quantity > 1) {item.quantity--;}},// 刪除商品removeItem(id) {if (confirm('確定要刪除這個商品嗎?')) {// 根據id查找商品索引const index = this.cartItems.findIndex(item => item.id === id);if (index !== -1) {// 從數組中刪除商品this.cartItems.splice(index, 1);}}},// 結算方法checkout() {// 檢查是否有選中的商品if (this.selectedCount === 0) {alert('請至少選擇一件商品');return;}// 顯示結算信息alert(`您已選擇${this.selectedCount}件商品,總計:¥${this.totalPrice},感謝購買!`);// 實際應用中這里應該跳轉到結算頁面或發送請求到后端// 為了演示,我們僅移除已選中的商品this.cartItems = this.cartItems.filter(item => !item.checked);}},watch: {// 深度監聽購物車數據變化cartItems: {handler(newValue) {// 將購物車數據保存到本地存儲localStorage.setItem('vue-cart', JSON.stringify(newValue));},deep: true // 深度監聽對象內部的變化}},created() {// 從本地存儲加載購物車數據const savedCart = localStorage.getItem('vue-cart');if (savedCart) {this.cartItems = JSON.parse(savedCart);}}});</script>
</body>
</html>

8. Vue知識點解析

通過這個項目,我們學習了以下Vue的知識點:

8.1 數據渲染與綁定

  • 插值表達式 {{ }}:顯示變量內容
  • v-model:雙向數據綁定,用于表單輸入和應用數據之間的綁定
  • v-model.number:自動將輸入值轉換為數字類型

8.2 條件渲染與列表渲染

  • v-if/v-else:根據條件決定是否渲染元素
  • v-for:遍歷數組渲染列表項
  • :key:為列表項提供唯一標識符,幫助Vue優化渲染

8.3 類與樣式綁定

  • :class:動態綁定CSS類,根據條件添加不同的類
  • 在本項目中,我們根據商品是否選中來添加不同的背景樣式

8.4 事件處理

  • @click:監聽點擊事件
  • 事件傳參:如@click="increaseQuantity(item.id)",可以向事件處理方法傳遞參數

8.5 計算屬性

  • computed:基于響應式依賴進行緩存,只有依賴更新時才重新計算
  • 計算屬性的getter和setter:如selectAll,可以通過getter獲取值,通過setter設置值

8.6 偵聽器

  • watch:監聽數據變化,執行相應操作
  • deep選項:深度監聽對象內部的變化
  • 在本項目中,我們使用偵聽器將購物車數據保存到本地存儲

8.7 生命周期鉤子

  • created:實例創建后執行代碼
  • 在本項目中,我們在created鉤子中從本地存儲加載購物車數據

8.8 屬性綁定

  • :src:alt:class:disabled等:動態綁定DOM元素的屬性

9. 功能擴展思路

以下是一些可以進一步擴展購物車功能的思路:

  1. 商品分類:按照商品分類進行分組顯示。

  2. 商品篩選:添加篩選功能,如按價格篩選、按品牌篩選等。

  3. 優惠券功能:添加優惠券選擇和應用功能。

  4. 庫存檢查:添加庫存數量限制,防止超出庫存購買。

  5. 收藏功能:允許用戶將商品移動到收藏夾。

  6. 推薦商品:在購物車底部顯示相關推薦商品。

  7. 批量操作:支持選中多個商品后批量刪除。

  8. 價格變動提醒:當商品價格變動時提醒用戶。

  9. 商品詳情鏈接:點擊商品名稱可以跳轉到商品詳情頁。

  10. 登錄注冊功能:添加用戶登錄注冊功能,將購物車與用戶賬號關聯。

10. 總結

通過本教程,我們使用Vue.js構建了一個功能完整的購物車應用。雖然這是一個小型應用,但它涵蓋了Vue的核心概念和實踐技巧。作為新手,你可以通過這個項目了解Vue的數據驅動和響應式特性,以及如何使用計算屬性、方法和偵聽器處理數據和用戶交互。

重點是,我們詳細介紹了以下關鍵功能的實現:

  1. 渲染功能:使用v-for高效渲染商品列表,通過:class動態綁定樣式,使選中的商品具有不同的背景色。

  2. 刪除功能:使用@click綁定刪除事件,獲取當前行的id,使用splice方法刪除數組中的元素。

  3. 修改數量:使用加減按鈕和輸入框控制商品數量,通過v-model.number確保輸入的是數字類型。

  4. 全選/反選:通過計算屬性的getter和setter實現全選/反選功能,使用every方法檢查是否所有商品都被選中。

  5. 統計功能:使用計算屬性自動計算選中商品的總數量和總價,保持數據的響應式更新。

  6. 本地存儲:使用偵聽器監聽購物車數據變化,自動保存到本地存儲,確保刷新頁面后數據不丟失。

希望這個教程能幫助你更好地理解Vue的基礎概念和應用開發流程。隨著你對Vue的深入學習,可以考慮使用Vue CLI、Vue Router、Vuex等進階技術來構建更復雜的應用。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/84052.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/84052.shtml
英文地址,請注明出處:http://en.pswp.cn/web/84052.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

雙因子認證如何讓Windows系統登錄更安全?SLA操作系統雙因素認證解決方案深度解析

引言&#xff1a;數字化轉型下的身份認證危機 在云計算與遠程辦公普及的2025年&#xff0c;企業信息系統正面臨前所未有的安全挑戰。微軟Azure Virtual Desktop漏洞事件、Citrix數據泄露等安全事件頻發&#xff0c;暴露出傳統密碼認證體系的致命缺陷。據《2025年云安全威脅報告…

FPGA基礎 -- Verilog語言要素之值集合

一、Verilog 值集合&#xff08;Value Set&#xff09; Verilog 是一種面向硬件建模的描述語言&#xff0c;為了更真實地模擬硬件行為&#xff0c;它并不僅僅像 C 語言那樣只有 0 和 1 兩種值&#xff0c;而是采用了四值邏輯&#xff08;Four-valued logic system&#xff09;…

開源一個芯片自由的脫機下載器

一、什么是脫機下載器 簡單來說&#xff0c;脫機下載器就是在不連接電腦、不用專業軟件的情況下&#xff0c;也能幫你把程序燒錄進芯片的工具。只要插上電源、按個按鈕&#xff0c;固件就自動下載進 MCU&#xff0c;非常適合量產、售后、維修等場景。 二、芯片自由的背后&…

Rust 學習筆記:關于模式匹配的練習題

Rust 學習筆記&#xff1a;關于模式匹配的練習題 Rust 學習筆記&#xff1a;關于模式匹配的練習題問題一問題二問題三 Rust 學習筆記&#xff1a;關于模式匹配的練習題 參考視頻&#xff1a; https://www.bilibili.com/video/BV1YxojYJESm 問題一 以下代碼能否通過編譯&…

利用tkinter函數構造MD5加密的可視化操作界面

GitHub文檔地址&#xff1a; https://github.com/gao7025/auto_entry_md5.git 引言 利用tkinter構造一個圖形界面的創建函數&#xff0c;主要實現了文件選擇、MD5加密處理、結果預覽和下載等功能。下面是主要涉及的功能模塊&#xff1a;主框架、文件選擇部分、MD5加密部分、結…

ICEM CFD網格生成 | 基本概念與界面工具

基本概念◆ 名稱定義 網格&#xff1a;網格是空間離散的單元&#xff0c;用于如下數值仿真 結構 流體 電磁 其他 單元 0D – 節點單元 質量點 約束&#xff0c;加載位置 1D –線單元 Bars, beams, rods, springs 2D 網格邊界 2D – 表面/殼單元 - 四邊形 - 三角…

簡化您的工作流程:在 Azure 中構建高效的邏輯應用程序

簡介 在當今的數字化環境中,自動化工作流程和服務集成對于追求效率和敏捷性的企業至關重要。Azure Logic Apps 使開發人員和 IT 專業人員能夠創建集成應用、數據、服務和系統的自動化工作流程。在本文中,我們將逐步講解使用 Azure 門戶創建 Logic Apps 的過程,并通過演示來說…

AI 技術落地實戰:開發流程優化、行業場景重塑與前沿應用洞察

在人工智能技術如火如荼發展的當下&#xff0c;AI 工具、大模型以及它們在各行業的應用&#xff0c;正以前所未有的態勢重塑著開發者的工作模式和各領域的發展格局。從智能編碼助手讓編程變得高效便捷&#xff0c;到自動化測試平臺提升軟件質量&#xff0c;從大模型在垂直行業的…

文本生成AI+圖像識別:電商詳情頁信息提取實戰

行業問題&#xff1a;傳統采集難以應對“圖文視頻化”的電商信息 在電商平臺不斷“視頻化”的趨勢下&#xff0c;傳統的網頁采集手段正逐漸失效。以抖音為例&#xff0c;商品信息已不僅限于圖文詳情&#xff0c;而是通過短視頻、圖像混排、語音解說等形式呈現。商品的名稱、優…

linux權限基礎

權限的概念 linux中&#xff0c;權限是用于控制【用戶】對 【文件】進行操作控制的工具。用戶權限文件權限 用戶權限 用戶 用戶組&#xff1a;具有相同特性的用戶的集合體。 文件權限 linux中&#xff0c;一切皆文件&#xff0c;包括普通文件&#xff0c;目錄&#xff0c;文件…

讓C++處理JSON類型配置文件更輕松-Hjson-cpp詳解

讓C處理JSON類型配置文件更輕松-Hjson-cpp詳解 一、Hjson-Cpp簡介Hjson-Cpp簡介核心特性安裝與集成基本用法示例常用API說明與JSON互轉錯誤處理性能建議高級特性1. 類型安全訪問2. 文件操作3. 自定義解析規則 二、使用教程下載使用 一、Hjson-Cpp簡介 Hjson-Cpp簡介 Hjson-Cp…

單例模式的好處

為什么要使用單例模式 1.資源管理&#xff1a; 唯一性&#xff1a;某些資源在整個應用程序中只需要一個實例&#xff0c;例如日志記錄器、配置管理器、數據庫連接池等。單例模式可以確保這些資源的唯一性&#xff0c;避免重復創建和管理。 全局訪問&#xff1a;單例模式提供了…

LangChain 結構化輸出指南

LangChain 結構化輸出指南 概述 對于許多應用程序&#xff08;如聊天機器人&#xff09;&#xff0c;模型需要直接用自然語言回應用戶。然而&#xff0c;在某些場景下&#xff0c;我們需要模型以結構化格式輸出。例如&#xff0c;我們可能希望將模型輸出存儲在數據庫中&#…

探究webView與html的通訊

最近出來個新需求&#xff1a; 需求描述&#xff1a; 將uniapp的代碼打包成一個app&#xff0c;并實現原本的功能。 原uniapp是一個H5項目&#xff0c;主要的步驟流程是上傳用戶的身份證進行二要素認證&#xff0c;成功后再進行三方活體認證&#xff0c;然后三方回跳到項目中的…

高級定時器TIM1、TIM8

高級定時器在通用定時器的基礎上增加了一些功能&#xff0c;如&#xff1a;重復計數器、帶死區控制的互補輸出通道、斷路輸入等。 捕獲/比較通道的輸出部分(通道1至3) 捕獲/比較通道的輸出部分(通道4) ①重復計數器RCR 基本和通用定時器發生溢出時&#xff0c;會直接生成更新時…

搭建簡易采購系統:從需求分析到供應商數據庫設計

一、需求分析框架&#xff08;4大核心模塊&#xff09; 關鍵需求清單&#xff1a; 需求提報&#xff08;含審批流&#xff09; 供應商準入與評估 比價與訂單生成 基礎報表功能 二、技術選型方案 組件推薦方案替代方案前端框架Vue.js ElementUIReact Ant Design后端語言P…

基于LSTM-GARCH混合模型的“獲利了結”量化解析:黃金單日1.27%跌幅的技術性歸因

摘要&#xff1a;本文通過多維度量化指標、結合地緣風險溢價因子、貨幣政策預期指數及貿易摩擦不確定性指數&#xff0c;構建動態情景分析框架。 一、黃金價格技術面解析 周一&#xff08;6月16日&#xff09;現貨黃金呈現"沖高回落-獲利了結"典型特征&#xff0c;日…

【AI】Spring AI Alibaba 的介紹

目錄 一、Spring AI Alibaba 的介紹 1.1 什么是 Spring AI Alibaba&#xff1f; 1.2 Spring AI 項目簡介 二、核心概念 2.1 模型 2.2 提示&#xff08;Prompt&#xff09; 2.3 提示詞模板&#xff08;Prompt Template&#xff09; 2.4 嵌入&#xff08;Embedding&#x…

從main()函數的執行發散開來

大多數程序員的第一行代碼可能都是從輸出“Hello&#xff0c;World!開始的吧。如果請你寫一個c程序&#xff0c;在屏幕上打印“Hello&#xff0c;World!”&#xff0c;下面的代碼對擁有扎實編程基本功的你而言肯定so easy&#xff1a; #include <stdio.h>int main() {pr…

(16)java+ selenium->自動化測試-元素定位之By xpath下篇

1.簡介 老規矩,我們還是接著前面兩篇的Xpath 5.自動測試實戰 以百度首頁為例,將xpath的各種定位方法一一講解和分享一下。 5.1大致步驟 1.訪問百度首頁。 2.通過xpath定位到元素,點擊一下。 5.2模糊定位starts-with關鍵字 有一種特殊的情況:頁面元素的屬性值會被動態…