我的Vue之旅 11 Vuex 實現購物車

来源:https://www.cnblogs.com/linxiaoxu/archive/2022/11/24/16920688.html
-Advertisement-
Play Games

Vue CartView.vue script 數組的filter函數需要return顯式返回布爾值,該方法得到一個新數組。 使用Vuex store的modules方式,註意讀取狀態的方式 this.$store.state.cart.items 刷新頁面後state狀態還原,需要用session ...


Vue

image-20221124022602927

CartView.vue script

  • 數組的filter函數需要return顯式返回布爾值,該方法得到一個新數組。
  • 使用Vuex store的modules方式,註意讀取狀態的方式 this.$store.state.cart.items
  • 刷新頁面後state狀態還原,需要用session保存狀態(TODO)
  • axios 發出 get 請求,第二個參數對象的 params 欄位值顯式使用 JSON.stringify 進行轉化,如果不使用會表示成 xxx?items=xxx&items=xxx&items=xxx
<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  name: "CartView",
  components: {},
  methods: {
    deleteItem(id: number) {
      this.$store.dispatch("del", id);
      console.log(this.$store.state.cart.items);
      this.items = this.items.filter((item) => {
        return item.id != id; // @ return
      });
    },
  },
  data() {
    return {
      days: 29,
      hours: 8,
      minutes: 20,
      discount: 24,
      items: [
        {
          id: 201,
          img: "https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_201.png",
          name: "Family",
          price: 2.99,
          author: "Tim Sheinman",
          category: "Puzzle",
        }
      ],
    };
  },
  computed: {
    cost() {
      let total = 0;
      this.items.forEach((item) => {
        total += item.price;
      });
      total *= (100 - this.discount) / 100;
      const res = total.toFixed(2);
      return res;
    },
  },
  created() {
    this.axios
      .get("/game/query", {
        params: {
          items: JSON.stringify(this.$store.state.cart.items),
        },
      })
      .then((response) => {
        if (!response.data) {
          console.log("無數據");
          return;
        }
        this.items = [];
        response.data.forEach((item: any) => {
          this.items.push({
            id: item.id,
            img: item.img,
            name: item.title,
            price: item.price,
            author: item.author,
            category: item.category,
          });
        });
      })
      .catch((err) => {
        console.log(err);
      });
  },
});
</script>

CartView.vue template

<template>
  <div class="m-3">
    <div class="text-3xl font-bold text-stone-700">
      <b-icon-cart-check
        class="text-4xl inline-block align-text-top mr-2"
      ></b-icon-cart-check
      >My Cart
    </div>
    <div class="text-stone-600 mt-4">
      Buy everything for
      <span class="font-bold">${{ cost }}! </span>
      <span class="font-bold">Save {{ discount }}%!</span>
    </div>
    <div class="mt-4 border border-stone-300 rounded-sm">
      <div
        class="
          mx-2
          h-10
          text-center
          pt-2.5
          m-auto
          mt-2
          bg-rose-500
          font-bold
          text-white
          rounded
        "
      >
        Buy all for ${{ cost }}
      </div>
      <div class="mt-2 text-center text-stone-500 text-sm">offer ends in</div>
      <div class="text-center">
        <div class="inline-block m-1">
          <div>{{ days }}</div>
          <div class="text-xs text-stone-500">DAYS</div>
        </div>
        <div class="inline-block m-1">
          <div>{{ hours }}</div>
          <div class="text-xs text-stone-500">HOURS</div>
        </div>
        <div class="inline-block m-1">
          <div>{{ minutes }}</div>
          <div class="text-xs text-stone-500">MINUTES</div>
        </div>
      </div>
    </div>
    <div class="mt-4">
      <div>includes the following items:</div>
      <template v-for="(value, index) in items" :key="index">
        <div class="mt-3">
          <img class="inline-block h-28 rounded-md" :src="value.img" />
          <div class="inline-block ml-4">
            <div class="">
              <span class="font-bold">{{ value.name }}</span>
              <div
                class="
                  ml-2
                  inline-block
                  text-xs
                  bg-stone-500
                  rounded-sm
                  px-1
                  py-0.5
                  mt-1
                  text-center text-white
                "
              >
                ${{ value.price }}
              </div>
            </div>
            <div class="text-stone-500 text-sm">
              {{ value.author }}
            </div>
            <div class="text-stone-500 text-sm">
              {{ value.category }}
            </div>
            <b-icon-x-square
              @click="deleteItem(value.id)"
              class="text-3xl mt-2"
            ></b-icon-x-square>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

store/cart.ts

VUE裡面的export default 是什麼_啊了個嗚的博客-CSDN博客

const state = {
  items: [
    // 201, 202, 203, 204
  ]
}

const mutations = {
  add(state: any, param: number) {
    if (!state.items.includes(param)) {
      state.items.push(param)
    }
  },
  del(state: any, param: number) {
    if (state.items.indexOf(param) != -1) {
      state.items.splice(state.items.indexOf(param), 1)
    }
  }
}

const actions = {
  add(context: any, param: number) {  // 可以 {commit} 解構簡化
    context.commit('add', param)
  },
  del(context: any, param: number) { 
    context.commit('del', param)
  }
}

const cart = {
  state,
  mutations,
  actions
}

export default cart

store/index.ts

import { createStore } from 'vuex'
import cart from './cart'

export default createStore({
  modules: {
    cart: cart
  }
})

Property ‘$store‘ does not exist on type ‘CreateComponentPublicInstance

src文件夾下新建文件夾vue.d.ts

// vuex.d.ts
import { ComponentCustomProperties } from '@/vue'
import { Store } from 'vuex'

declare module '@vue/runtime-core' {
  // declare your own store states
  interface State {
    cart
  }

  // provide typings for `this.$store`
  interface ComponentCustomProperties {
    $store: Store<State>
  }
}

三種方法實現Vue路由跳轉時自動定位在頁面頂部

image-20221124023109106
// 跳轉後自動返回頁面頂部
router.afterEach(() => {window.scrollTo(0,0);
})

const router = new VueRouter({routes:[...],scrollBehavior () {// return返回期望滾動到的位置的坐標return { x: 0, y: 0 }}
})

router.beforeEach((to, from, next) => {    // chrome相容document.body.scrollTop = 0// firefox相容document.documentElement.scrollTop = 0// safari相容window.pageYOffset = 0next()
})

Golang Gin

structs/game.go

package structs

type Game struct {
	ID       int64   `db:"id" json:"id"`
	Title    string  `db:"title" json:"title"`
	Text     string  `db:"text" json:"text"`
	Img      string  `db:"img" json:"img"`
	Author   string  `db:"author" json:"author"`
	Category string  `db:"category" json:"category"`
	Price    float64 `db:"price" json:"price"`
}

controller/game.go

image-20221124022438383

package controller

import (
	"encoding/json"
	"fmt"

	"github.com/gin-gonic/gin"
	"wolflong.com/vue_gin/structs"
	"wolflong.com/vue_gin/variable"
)

func QueryGame(c *gin.Context) {
	db := variable.DB
	items_ := c.Query("items")
	var items []int64
	err := json.Unmarshal([]byte(items_), &items)
	if err != nil || len(items) == 0 {
		c.JSON(501, gin.H{
			"message": "failure items",
		})
		c.Abort()
		return
	}
	// fmt.Println(items)
	stmt := `select id,title,author,category,img,price from game where id in (`
	for i, v := range items {
		stmt += fmt.Sprintf("%d", v)
		if i != len(items)-1 {
			stmt += ","
		}
	}
	stmt += ")"
	rows, err := db.Query(stmt)
	checkError(err)
	defer rows.Close()
	var res []structs.Game
	for rows.Next() {
		var c structs.Game
		err = rows.Scan(&c.ID, &c.Title, &c.Author, &c.Category, &c.Img, &c.Price)
		checkError(err)
		res = append(res, c)
	}
	c.JSON(200, res)
}

router/router.go

新增路由

game := r.Group("/game")
{
    game.GET("/query", controller.QueryGame)
}

Mysql 建表

DROP DATABASE VUE;
create database if not exists vue;
use vue;

CREATE TABLE gameblog (
  id INT PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(255),
  text VARCHAR(255),
  img VARCHAR(255)
);

insert into gameblog(title,text,img) values 
("Games of the Month: surrealist solitaire puzzles","What’s that? You need more games? I hear you, anonymous hapi fan.We’ve reached the part of the year when games start coming out fast","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102184434_1.jpg"),
("Games of the Month: Puzzles!","Sometimes you need a good puzzle game, just something to throw all of your attention at and ignore anything else going on. Well if that sometime for you is right now, then you’re in luck because in this Games of the Month","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102184434_2.jpg"),
("The next hapi Creator Day is July 29th!","I don’t think I’m allowed to make the entire body of this post “Thenext itch.io Creator Day is taking place on Friday July 29th.” I mean it’s true, we are hosting the next itch.io Creator Day on Friday July 29th but I should probably write more here.","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102184434_3.jpg");

select * from gameblog;

drop table if exists game;
CREATE TABLE game (
  id INT PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(255),
  text VARCHAR(255),
  img VARCHAR(255),
  author VARCHAR(255) default "", # TODO ID
  category VARCHAR(255) default "", # TODO ID
  price decimal(6,2) default 0,
  web boolean default 0
  # TODO 發佈時間
  # TODO 瀏覽量
  # TODO 評論量
  # TODO 熱度綜合指標
);

CREATE TABLE tag (
  id INT PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(255)
);

CREATE TABLE gametag (
  gameid INT,
  tagid INT
);
# TODO 外鍵

insert into game(id,title,author,category,text,img,price,web) values
(1,"Late Night Mop","","","A haunted house cleaning simulator.","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102193135_1.png",0,0),
(2,"an average day at the cat cafe","A haunted house cleaning simulator.","","","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102193135_2.png",0,1),
(3,"Corebreaker","A fast-paced action-platform shooter game with roguelike elements.","","","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102193135_3.png",19.99,0),
(4,"Atuel","Traverse a surrealist landscape inspired by the Atuel River in Argentina.","","","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221102193135_5.png",0,0),
(201,"Family","Tim Sheinman","Puzzle","TEST","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_201.png",2.99,0),
(202,"Rivals","dreamfeel","Puzzle","TEST","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_202.png",5.99,0),
(203,"Conspiracy!","Tim Sheinman","Puzzle","TEST","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_203.png",4.99,0),
(204,"Riley & Rochelle","Nolski","Puzzle","TEST","https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_204.png",14.99,0)
;
select * from game;


insert into tag values
(1,"Difficult"),
(2,"Fast-Paced");

insert into gametag values
(3,1),
(3,2),
(4,1);

DELIMITER $$
CREATE PROCEDURE gamelist()
BEGIN
	# TODO
END $$
DELIMITER ;

select a.title,a.text,img,price,web,if(group_concat(c.title separator "#") is null ,"", group_concat(c.title separator "#")) as tag from game a left join gametag b on a.id = b.gameid left join tag c on b.tagid = c.id group by a.id;


drop table if exists users;
drop table if exists comments;

create table users(
id int primary key auto_increment,
uid varchar(255),
name varchar(255),
password varchar(255)
);

create table comments(
id int primary key auto_increment,
uid int,
text mediumtext,
pid int,
date long
);

insert into users(uid,name,password) values
("1001","admin","123456"),
("1002","玉米燉蘿蔔","123456"),
("1003","西紅柿炒番茄","123456");

INSERT INTO comments(id, uid, text, pid, date) VALUES (1, 1003, 'asdmoapsdasopdnopasdopasopdas localstorage', 100, 1666107328334);
INSERT INTO comments(id, uid, text, pid, date) VALUES (2, 1003, 'asdmoapsdasopdnopasdopasopdas localstorage', 100, 1666107328836);
INSERT INTO comments(id, uid, text, pid, date)  VALUES (3, 1003, 'asdmoapsdasopdnopasdopasopdas localstorage', 100, 1666107329459);
INSERT INTO comments(id, uid, text, pid, date)  VALUES (4, 1001, 'asdmoapsdasopdnopasdopasopdas localstorage', 100, 1666107331864);
INSERT INTO comments(id, uid, text, pid, date)  VALUES (5, 1001, 'asdmoapsdasopdnopasdopasopdas localstorage', 100, 1666107332720);
INSERT INTO comments(id, uid, text, pid, date)  VALUES (6, 1002, '你好', 100, 1666107337646);

select * from users;
select * from comments;
select * from game;

drop table if exists posts;
create table posts(
id int primary key auto_increment,
bgcolor varchar(7),
textcolor varchar(7),
headimg varchar(255),
videosrc varchar(255),
imgs mediumtext,
html mediumtext
);

insert into posts(id,bgcolor,textcolor,headimg,videosrc,imgs,html) values
(
100,
"#E8E1BC",
"#2f5b71",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109232741_head.png",
"https://www.youtube.com/embed/zGGTLStyKX0",
'["https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109233251_1.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109233256_4.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109233253_2.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109233255_3.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109233258_5.png"]
',
'<div class="m-4 text-xl font-bold">
      A sound reverberated from beyond the ocean.
    </div>
    <div class="ml-4 mt-6">
      At the edge of a desolate island, pick up what the waves wash ashore to
      make instruments. Use those instruments to answer the echoes heard from
      beyond the ocean. In this hand-drawn world, enjoy a soothing soundscape
      formed by waves, footsteps and the sounds made from things washed up.
    </div>
    <img
      src="https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221109231919_play.gif"
      class="w-full mt-6 px-4"
    />
    <div class="ml-4 mt-6">
      Resonance of the Ocean is a short adventure game you can play in 10 ~
      30min. This game was made in the 22nd unity1week, a Japanese game jam
      event. This version is updated with an English localization and with small
      changes. In unity1week, this game placed 4th in the overall ranking, and
      1st for art and sound.
    </div>
    <div class="m-4 mt-6 text-xl font-bold">Controls</div>
    <div class="ml-4 mt-6">
      This game only supports keyboard controls.
      <ul class="list-disc ml-6 mt-2">
        <li>Arrow Keys: Move</li>
        <li>Space Key(Or ZXC): Confirm</li>
        <li>ZXC Keys: pick up, replace, throw, search</li>
      </ul>
    </div>
    <div class="m-4 mt-6 text-xl font-bold">Save Function</div>
    <div class="ml-4 mt-6">
      There is no save function available as the time required to complete the
      game is short (10 ~ 30 min). Thank you for your understanding.
    </div>'
),
(
101,
"#FFFFFF",
"#000000",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004301_head2.png",
"https://www.youtube.com/embed/vddlEmrbNRw",
'["https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_7.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_8.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_9.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_10.png"]
',
'
<div class="ml-4 mt-6">
      The past and future cannot be explored alone! Team up with a friend and
      piece together the mysteries surrounding Albert Vanderboom. Communicate
      what you see around you to help one another solve various puzzles and
      explore the worlds from different perspectives!
    </div>
    <div class="ml-4 mt-6">
      The Past Within is the first <a class="underline">co-op</a> only
      point-and-click adventure set in the mysterious world of Rusty Lake.
    </div>
    <div class="m-4 mt-6 text-xl font-bold">Features</div>
    <div class="ml-4 mt-6">
      <ul class="list-disc ml-6 mt-2">
        <li class="font-bold">A co-op experience</li>
        Play together with a friend, one in The Past, the other in The Future.
        Work together to solve the puzzles and help Rose set her father’s plan
        in motion!
        <li class="font-bold">Two worlds - Two perspectives</li>
        Both players will experience their environments in two different
        dimensions: 2D as well as in 3D - a first-time experience in the Rusty
        Lake universe!
        <li class="font-bold">Cross-platform play</li>
        As long as you can communicate with each other, you and your partner of
        choice can each play The Past Within on your preferred platform: PC,
        Mac, iOS, Android and (very soon) Nintendo Switch!
        <li class="font-bold">Playtime & Replayability</li>
        The game contains 2 chapters and has an average play-time of 2 hours.
        For the full experience, we recommend replaying the game from the other
        perspective. Plus you can use our replayability feature for a fresh
        start with new solutions to all puzzles.
      </ul>
    </div>
    '
),
(
201,
"#FFFFFF",
"#000000",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_201.png",
"https://www.youtube.com/embed/vddlEmrbNRw",
'["https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_7.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_8.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_9.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_10.png"]
',
'
<div class="ml-4 mt-6">
	測試測試測試
    </div>
    '
),
(
202,
"#FFFFFF",
"#000000",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_202.png",
"https://www.youtube.com/embed/vddlEmrbNRw",
'["https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_7.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_8.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_9.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_10.png"]
',
'
<div class="ml-4 mt-6">
	測試測試測試
    </div>
    '
),
(
203,
"#FFFFFF",
"#000000",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_203.png",
"https://www.youtube.com/embed/vddlEmrbNRw",
'["https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_7.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_8.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_9.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_10.png"]
',
'
<div class="ml-4 mt-6">
	測試測試測試
    </div>
    '
),
(
204,
"#FFFFFF",
"#000000",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221123235723_204.png",
"https://www.youtube.com/embed/vddlEmrbNRw",
'["https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_7.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_8.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_9.png",
"https://xiaonenglife.oss-cn-hangzhou.aliyuncs.com/static/pic/2022/11/20221110004259_10.png"]
',
'
<div class="ml-4 mt-6">
	測試測試測試
    </div>
    '
)
;

select * from posts;

drop table if exists sellopts;
create table sellopts(
	id int primary key auto_increment,
	days int,
    hours int,
    minutes int,
    discount int
);
insert into sellopts(id,days,hours,minutes,discount) values
(1,29,8,20,24);


select id,bgcolor,textcolor,headimg,videosrc,imgs,html from posts where id = 100

JS 數組方法

JavaScript Array 對象 | 菜鳥教程 (runoob.com)

Gin Query

Gin之獲取querystring參數_GoGo在努力的博客-CSDN博客

Gin Session

gin-contrib/sessions: Gin middleware for session management (github.com)

gin-contrib/sessions 筆記 | PJCHENder 未整理筆記


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 字元編碼與配置文件 \s查看MySQL相關信息 相關信息有:當前用戶、版本、編碼、埠號 MySQL5.6及之前的版本編碼需要人為統一 之後的版本已經全部預設統一 如果想要永久修改編碼配置 需要操作配置文件my-default.ini 註意事項: mysql預設埠號3306 當重覆起mysql服務 ...
  • 前幾天,Gartner 發佈了企業機構在2023年需要探索的十大戰略技術趨勢。 Gartner 傑出研究副總裁 Frances Karamouzis 表示:“為了在經濟動蕩時期增加企業機構的盈利,首席信息官和IT高管必須在繼續加快數字化轉型的同時,將目光從節約成本轉向新的卓越運營方式。Gartner ...
  • ChunJun(原FlinkX)是一個基於 Flink 提供易用、穩定、高效的批流統一的數據集成工具。2018年4月,秉承著開源共用的理念,數棧技術團隊在github上開源了FlinkX,承蒙各位開發者的合作共建,FlinkX得到了快速發展。 兩年後的2022年4月,技術團隊決定對FlinkX進行整 ...
  • 首發微信公眾號:SQL資料庫運維 原文鏈接:https://mp.weixin.qq.com/s?__biz=MzI1NTQyNzg3MQ==&mid=2247485212&idx=1&sn=450e9e94fa709b5eeff0de371c62072b&chksm=ea37536cdd40da7 ...
  • 一、SQL與NoSQL ​ 資料庫服務端可以服務多種類型的客戶端 ​ 客戶端可以是自己開發的,也可以是python代碼編寫的,也可以是其他編程語言編寫的 SQL 操作關係型數據的語言 NoSQL 操作非關係型數據的語言 須知: ​ 1、SQL有時又也指代關係型資料庫 ​ 2、NoSQL有時候也指代非 ...
  • Android網路請求(終) 網路請求框架Retrofit Retrofit底層是由OkHttp封裝的,Retrofit對於註解的使用十分頻繁,所以不瞭解註解的同學們可以去查查資料什麼的。 這裡有一個小細節,要使用Retrofit至少需要jdk1.8以上和Android API 21以上 Andro ...
  • Android網路請求(4) 網路請求框架Volley Volley是Google在2013年5月15日到17日在舊金山Moscone中心舉辦網路開發者年會中推出的Android非同步網路載入框架和圖片載入框架,它特別適合數據體量小且通訊頻繁的網路操作場景,而Android開發中大多數場景都是這樣的, ...
  • 華為HMS Core音頻編輯服務(Audio Editor Kit)依托自身AI技術的研發優勢,上線全新的歌聲合成音色及伴奏,給音視頻創作者提供更多的創作可能。在短視頻場景中,用戶自定義歌詞的歌聲結合視頻讓用戶感受到身臨其境,自由表達自己的情緒;在虛擬偶像場景中,歌聲合成功能賦予虛擬歌手們演唱風格各 ...
一周排行
    -Advertisement-
    Play Games
  • 概述:在C#中,++i和i++都是自增運算符,其中++i先增加值再返回,而i++先返回值再增加。應用場景根據需求選擇,首碼適合先增後用,尾碼適合先用後增。詳細示例提供清晰的代碼演示這兩者的操作時機和實際應用。 在C#中,++i 和 i++ 都是自增運算符,但它們在操作上有細微的差異,主要體現在操作的 ...
  • 上次發佈了:Taurus.MVC 性能壓力測試(ap 壓測 和 linux 下wrk 壓測):.NET Core 版本,今天計劃準備壓測一下 .NET 版本,來測試並記錄一下 Taurus.MVC 框架在 .NET 版本的性能,以便後續持續優化改進。 為了方便對比,本文章的電腦環境和測試思路,儘量和... ...
  • .NET WebAPI作為一種構建RESTful服務的強大工具,為開發者提供了便捷的方式來定義、處理HTTP請求並返迴響應。在設計API介面時,正確地接收和解析客戶端發送的數據至關重要。.NET WebAPI提供了一系列特性,如[FromRoute]、[FromQuery]和[FromBody],用 ...
  • 原因:我之所以想做這個項目,是因為在之前查找關於C#/WPF相關資料時,我發現講解圖像濾鏡的資源非常稀缺。此外,我註意到許多現有的開源庫主要基於CPU進行圖像渲染。這種方式在處理大量圖像時,會導致CPU的渲染負擔過重。因此,我將在下文中介紹如何通過GPU渲染來有效實現圖像的各種濾鏡效果。 生成的效果 ...
  • 引言 上一章我們介紹了在xUnit單元測試中用xUnit.DependencyInject來使用依賴註入,上一章我們的Sample.Repository倉儲層有一個批量註入的介面沒有做單元測試,今天用這個示例來演示一下如何用Bogus創建模擬數據 ,和 EFCore 的種子數據生成 Bogus 的優 ...
  • 一、前言 在自己的項目中,涉及到實時心率曲線的繪製,項目上的曲線繪製,一般很難找到能直接用的第三方庫,而且有些還是定製化的功能,所以還是自己繪製比較方便。很多人一聽到自己畫就害怕,感覺很難,今天就分享一個完整的實時心率數據繪製心率曲線圖的例子;之前的博客也分享給DrawingVisual繪製曲線的方 ...
  • 如果你在自定義的 Main 方法中直接使用 App 類並啟動應用程式,但發現 App.xaml 中定義的資源沒有被正確載入,那麼問題可能在於如何正確配置 App.xaml 與你的 App 類的交互。 確保 App.xaml 文件中的 x:Class 屬性正確指向你的 App 類。這樣,當你創建 Ap ...
  • 一:背景 1. 講故事 上個月有個朋友在微信上找到我,說他們的軟體在客戶那邊隔幾天就要崩潰一次,一直都沒有找到原因,讓我幫忙看下怎麼回事,確實工控類的軟體環境複雜難搞,朋友手上有一個崩潰的dump,剛好丟給我來分析一下。 二:WinDbg分析 1. 程式為什麼會崩潰 windbg 有一個厲害之處在於 ...
  • 前言 .NET生態中有許多依賴註入容器。在大多數情況下,微軟提供的內置容器在易用性和性能方面都非常優秀。外加ASP.NET Core預設使用內置容器,使用很方便。 但是筆者在使用中一直有一個頭疼的問題:服務工廠無法提供請求的服務類型相關的信息。這在一般情況下並沒有影響,但是內置容器支持註冊開放泛型服 ...
  • 一、前言 在項目開發過程中,DataGrid是經常使用到的一個數據展示控制項,而通常表格的最後一列是作為操作列存在,比如會有編輯、刪除等功能按鈕。但WPF的原始DataGrid中,預設只支持固定左側列,這跟大家習慣性操作列放最後不符,今天就來介紹一種簡單的方式實現固定右側列。(這裡的實現方式參考的大佬 ...