發表文章

Vue + Vite 專案部署到 Nginx pinia 模組錯誤

問題說明 當你將 Vue + Vite 專案部署到 Nginx,並在瀏覽器開啟網站時,可能會遇到以下錯誤: Uncaught TypeError: Failed to resolve module specifier "pinia". Relative references must start with either "/", "./", or "../". 這是因為你部署的是 原始碼 ,而不是 Vite 打包後的 dist/ 資料夾 。 解決方案:部署   dist  打包資料夾 以下是完整部署步驟: 設定 Nginx 指向   dist/ 資料夾 請確認你的 Nginx 設定如下所示,將 root 設定為打包後的 dist/ 路徑: server { listen 80; server_name yourdomain.com; root /var/www/your-project/dist; index index.html; location / { try_files $uri $uri/ /index.html; } } 請將 /var/www/your-project/dist 改成你的實際路徑。 try_files 的設定能夠正確處理 Vue 的前端路由(SPA 模式)。 設定完成後,重新啟動 Nginx: sudo systemctl restart nginx 最終確認 部署完成後,瀏覽器應該能正常載入所有模組(例如 pinia ),不會再出現錯誤訊息。

如何避免使用者使用上一頁回來

解1. 因為不想讓使用者按上一頁,回來看到本頁,所以判斷當使用者按上一頁進來時,回到上一頁。 window.addEventListener('pageshow', function (event) {     if(event.persisted || window.performance && window.performance.navigation.type == 2){         window.history.go(-1);     } },false); window.performance.navigation.type 屬性包含了頁面導航的類型。該屬性可以用來判斷頁面是如何被訪問的。 屬性值 0:TYPE_NAVIGATE:使用者通過常規導航方式訪問頁面,比如點擊一個連結,或者一般的 get 方式。 1:TYPE_RELOAD:使用者通過刷新,包括 JavaScript 調用刷新接口等方式訪問頁面。 2:TYPE_BACK_FORWARD:使用者通過後退按鈕訪問本頁面。   參考來源: https://blog.csdn.net/weixin_41190571/article/details/87970446 解2. 使用window.replace方法,讓頁面不產生紀錄,不讓使用者可以回到上一頁。

使用 ssh terminal連線cloudflare tunnels伺服器

圖片
在完成cloudflare tunnel SSH設定後,想要用terminal對Server進行連線,如果還沒完成設定請參考: https://lanwp.org/15-how-to-use-cloudflaretunnel-build-webbase-sshterminal/ 發現怎麼樣都無法透過SSH連線到自己的伺服器 經過爬文發現需要透過cloudflare的驗證才能連線上,參考來源: https://community.cloudflare.com/t/about-connect-as-a-user-ssh-client-windows-10/524994 1.下載cloudflare的程式 https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/ ,放在路徑"C:\Users\{user}\.ssh\cloudflared-windows-amd64.exe",linux的話路徑為/usr/local/bin/cloudflared 2.編輯檔案"C:\Users\{user}\.ssh\config" Host example.com     HostName example.com     ProxyCommand C:\Users\{user}\.ssh\cloudflared-windows-amd64.exe access ssh --hostname %h     User user 完成後就可以透過terminal完成連線!

訪問者模式(Visitor Pattern)以PHP為例

訪問者模式(Visitor Pattern)是一種行為型設計模式,它用於將操作從元素的結構中分離出來。這種模式可以讓我們在不修改元素類別的情況下,定義新的操作。 以下是一個使用 PHP 語言的訪問者模式重構案例: // 元素接口 interface Element {     public function accept(Visitor $visitor): void; } // 具體元素 A class ConcreteElementA implements Element {     public function accept(Visitor $visitor): void {         $visitor->visitConcreteElementA($this);     }     public function operationA(): string {         return "ConcreteElementA: Operation A";     } } // 具體元素 B class ConcreteElementB implements Element {     public function accept(Visitor $visitor): void {         $visitor->visitConcreteElementB($this);     }     public function operationB(): string {         return "ConcreteElementB: Operation B";     } } // 訪問者接口 interface Visitor {     public function visitConcreteElementA(ConcreteElementA $elementA): void; ...

橋樑模式(Bridge Pattern)以PHP為例

橋樑模式(Bridge Pattern)是一種結構型設計模式,它將抽象和實作分離,使它們可以獨立變化。這種模式通常用於將類別的抽象部分與其實作部分分離,並且可以獨立地擴展和修改它們。 以下是一個使用 PHP 語言的橋樑模式重構案例: // 實作部分的介面 interface Implementation {     public function operationImplementation(): string; } // 具體的實作部分 A class ConcreteImplementationA implements Implementation {     public function operationImplementation(): string {         return "ConcreteImplementationA";     } } // 具體的實作部分 B class ConcreteImplementationB implements Implementation {     public function operationImplementation(): string {         return "ConcreteImplementationB";     } } // 抽象部分的類別 abstract class Abstraction {     protected $implementation;     public function __construct(Implementation $implementation) {         $this->implementation = $implementation;     }     public function operation(): string {         return "Abstraction:...

狀態模式(State Pattern) 以PHP為例

 狀態模式(State Pattern)是一種行為型設計模式,它允許物件在內部狀態發生變化時改變其行為。這種模式將物件的行為封裝在不同的狀態類別中,使得物件能夠根據當前的狀態選擇不同的行為。 以下是一個使用 PHP 實現狀態模式的重構案例: / / Context(上下文)類別維護著當前狀態物件並委派相關的請求給該狀態物件 class Context {     private $state;     public function __construct(State $state) {         $this->state = $state;     }     public function setState(State $state) {         $this->state = $state;     }     public function request() {         $this->state->handle($this);     } } // State(狀態)介面聲明了具體狀態類別應實現的方法 interface State {     public function handle(Context $context): void; } // ConcreteStateA(具體狀態A)實現 State 介面並提供具體的行為 class ConcreteStateA implements State {     public function handle(Context $context): void {         echo "ConcreteStateA: Handle\n";         // 狀態轉換         $context->setState(new C...

原型模式(Prototype Pattern) 以PHP為例

 原型模式(Prototype Pattern)是一種創建型設計模式,它通過複製現有物件來生成新物件,而不需要使用者知道具體的創建邏輯。這種模式通常用於當創建物件的成本很高昂或複雜時,並且希望通過複製現有物件來獲得新物件。 下面是一個使用 PHP 實現原型模式的重構案例: abstract class Prototype {     protected $name;     public function __construct($name) {         $this->name = $name;     }     abstract public function clone(): Prototype;     public function getName() {         return $this->name;     } } class ConcretePrototype extends Prototype {     public function clone(): Prototype {         return new ConcretePrototype($this->getName());     } } // 使用範例 $prototype = new ConcretePrototype('Prototype'); $clone = $prototype->clone(); echo $prototype->getName();  // Output: Prototype echo $clone->getName();  // Output: Prototype 在這個例子中,我們首先定義了一個抽象類別 `Prototype`,它包含一個抽象方法 `clone` 和一個共享的屬性 `name`。 `clone` 方法用於生成該物件的克隆,子類別必須實現這個方法。 `getName` 方法用於獲取...

輕量級模式(Flyweight Pattern) 以PHP為例

輕量級模式(Flyweight Pattern)是一種結構型設計模式,它旨在有效地支援大量細粒度的物件共享,以減少記憶體使用和提高效能。該模式通常在應用程式需要使用大量相似物件時使用。 以下是一個使用 PHP 實現輕量級模式的案例: // Flyweight(輕量物件)介面定義了共享物件的操作 interface Flyweight {     public function operation(): void; } // ConcreteFlyweight(具體輕量物件)實現 Flyweight 介面,並代表可共享的物件 class ConcreteFlyweight implements Flyweight {     private $name;     public function __construct($name) {         $this->name = $name;     }     public function operation(): void {         echo "ConcreteFlyweight: {$this->name}\n";     } } // FlyweightFactory(輕量工廠)負責創建和管理共享的輕量物件 class FlyweightFactory {     private $flyweights = [];     public function getFlyweight($name): Flyweight {         if (!isset($this->flyweights[$name])) {             $this->flyweights[$name] = new ConcreteFlyweight($name);         }     ...

單一職責原則 (Single Responsibility Principle,SRP) 以PHP為例

單一職責原則(Single Responsibility Principle,SRP)是一個軟體設計原則,它指出一個類別應該只有一個引起變化的原因。換句話說,一個類別應該只負責一個職責或功能。 以下是一個使用 PHP 進行單一職責原則重構的範例: class FileLogger {     private $filename;     public function __construct($filename) {         $this->filename = $filename;     }     public function log($message) {         file_put_contents($this->filename, $message, FILE_APPEND);     }     public function clearLog() {         file_put_contents($this->filename, '');     } } class User {     private $name;     private $logger;     public function __construct($name, FileLogger $logger) {         $this->name = $name;         $this->logger = $logger;     }     public function setName($name) {         $this->name = $name;         $this->logge...

依賴反轉原則(Dependency Inversion Principle, DIP) 以PHP為例

當我們談論依賴反轉原則(Dependency Inversion Principle,DIP)時,我們講的是高階模組(High-level Modules)不應該依賴於低階模組(Low-level Modules),兩者都應該依賴於抽象(Abstractions)。 下面是一個簡單的例子,展示如何使用 PHP 實現依賴反轉原則: interface MessageSenderInterface {     public function sendMessage($message); } class EmailSender implements MessageSenderInterface {     public function sendMessage($message) {         // 實現發送電子郵件的邏輯         echo "Sending email: " . $message . "\n";     } } class SMSsender implements MessageSenderInterface {     public function sendMessage($message) {         // 實現發送短信的邏輯         echo "Sending SMS: " . $message . "\n";     } } class NotificationService {     private $messageSender;     public function __construct(MessageSenderInterface $messageSender) {         $this->messageSender = $messageSender;     }     public function sendNoti...

php將運算子作為變數使用

是的,PHP 的運算子可以使用於變數上,只需要通過字串形式將運算子賦值給變數,然後再將變數作為運算子在運算式中使用即可。例如: $operator = '+'; $x = 1; $y = 2; $result = eval("return {$x} {$operator} {$y};"); 這樣就可以动態使用運算子。但需要注意的是,使用 eval 函數存在安全問題,因此需要谨慎使用。

php取得excel欄位的名稱

以下是一個產生 Excel 欄位名稱的 PHP 程式,可以將數字轉換為英文字母: function excelColumnName($columnNumber) {     $columnName = '';     while ($columnNumber > 0) {         $modulo = ($columnNumber - 1) % 26;         $columnName = chr(65 + $modulo) . $columnName;         $columnNumber = (int)(($columnNumber - $modulo) / 26);     }     return $columnName; } 使用方法如下: echo excelColumnName(1); // 顯示 A echo excelColumnName(2); // 顯示 B echo excelColumnName(26); // 顯示 Z echo excelColumnName(27); // 顯示 AA echo excelColumnName(28); // 顯示 AB 遇到錯誤Invalid cell coordinate \70的解決方案

laradock部屬 xdebug 修正 Could not connect to debugging client. Tried: host.docker.internal:9003問題

問題 使用laradock部屬啟動xdebug發現不斷跳出錯誤: Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(      始終不知道問題出在哪 解法 修改檔案 /etc/php/8.1/cli/conf.d/xdebug.ini (因設定有可能路徑不同) xdebug.mode=off 修改為     xdebug.mode=debug     

Laravel broadcast 踩雷記

 在一個功能裡有頻繁需要知道執行的狀態,並更新頁面的動作,因此找到了websocket的解決方案,來替代Ajax,結果一路踩雷,在這邊紀錄一下: broadcast環境設置參考,就不再贅述: https://blog.csdn.net/nsrainbow/article/details/80428769 1.啟動 laravel-echo-server後, env已經設定使用redis, 卻沒有接收到廣播 QUEUE_DRIVER=redis      反覆測試發現廣播都進入到laravel.log中,因此清理環境變數後,就正常了 php artisan config:cache php artisan config:clear 2.啟動 laravel-echo-server後,已經加入socket.io, 卻沒有登入訊息 可能是socket.io的bug,將npm的版本設定在2.3.0版,就可以看到登入訊息了 npm install --save-dev socket.io-client@2.3.0 3.在前端console一直看到 /socket.io/?EIO=3&transport=*&t=*&sid=* 403的錯誤訊息 伺服器的 port 6001沒有開 sudo ufw allow 3306 如果還是無效,應該要去檢查伺服器商或是router的設定

google ads 開發遇到 The developer token is not approved. Non-approved developer tokens can only be used with test accounts.

圖片
在開發google ads應用時遇到 Error with message "The developer token is not approved. Non-approved developer tokens can only be used with test accounts.". 研究了一下發現,要使用開發者帳號去開發只能使用測試客戶的資料,所以需要建立測試客戶,but找了很久都找不到建立的路口,後來發現了google的測試帳號建立路徑: https://adwords.google.com/um/Welcome/?sf=mt 點選按鈕 會發現頭像旁邊就有測試帳戶的字樣了 透過這樣的方式建立的帳戶id就可以加入設定中嚕~

在windows更新所有python套件

使用pip-review來協助更新 安裝後執行按a(All)即可 pip install pip-review pip-review --local --interactive 參考資料 https://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip

執行object detection 發生錯誤:cannot import name 'preprocessor_pb2'

執行object detection專案時,一切設定完成要進行train時 發生錯誤:cannot import name 'preprocessor_pb2' 解決方法: 執行指令: protoc object_detection/protos/*.proto --python_out=. 在https://github.com/tensorflow/models下載後 下來的根目錄 models / research /執行該指令

tesseract is not installed or it's not in your path

在進行驗證碼解析需要用到的python套件tesseract-ocr 始終會出現路徑找不到的問題 錯誤: tesseract is not installed or it's not in your path 解法: 修改套件原始路徑 C:\Users\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\pytesseract\pytesseract.py tesseract_cmd = 'tesseract' 改為 tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe' 將路徑改為另外安裝的Tesseract-OCR路徑就可以抓到了

It's not your fault

最近看完了心靈捕手的電影 一句『這不是你的錯』讓我久久不能自己,或許是因為最近的經歷,讓我有如此深刻的體悟,自己的運氣還不錯,有遇到自己的心靈導師,一直以來都希望自己是獨立而不用去麻煩別人的,努力充實自己的能力,嘗試著用自己的能力去賺錢,養活自己,總是兢兢業業的過著生活,每一天每一分鐘,都覺得呼吸的空氣會讓我窒息,但還是不想麻煩別人,不想將這份負能量傳達給任何人,這份自以為的“獨立”似乎是根生蒂固的在心裏,但社會總是現實,生活亦是,不管你做了多少努力,還是會重重的把你拍在地上,可能是能力不足,也可能是時間不夠,跟社會打交道了幾次,嗚著嘴壓抑著,眼淚還是留下來了,不能說的獨立還在,但懷抱著夢想的少年已經消失,曾經是對任何事都充滿熱情,勇於嘗試的自己,在近幾年已經看不見,我害怕,穩定就好了.

bcb C++ Builder無法讀取JPG

圖片
問題 使用C++ Builder TImage讀取圖片路徑 Image1->Picture->LoadFromFile("icant.jpeg"); 出現錯誤unknown picture file extension (.jpg) 解決方法 加入 #include <JPEG.HPP> 如果還不能使用,則調整圖片,如換張,或轉檔為jpg,jpeg,png等