<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web &#8211; 张三太爷</title>
	<atom:link href="https://www.somedoc.net/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.somedoc.net</link>
	<description>看前面，黑洞洞</description>
	<lastBuildDate>Sun, 03 Aug 2025 03:29:35 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://www.somedoc.net/wp-content/uploads/2016/12/cropped-dandycheung-1-32x32.jpg</url>
	<title>Web &#8211; 张三太爷</title>
	<link>https://www.somedoc.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>本站从 PHP 7.4 升级 8.4</title>
		<link>https://www.somedoc.net/2025/07/26/%e6%9c%ac%e7%ab%99%e4%bb%8e-php-7-4-%e5%8d%87%e7%ba%a7-8-4/</link>
					<comments>https://www.somedoc.net/2025/07/26/%e6%9c%ac%e7%ab%99%e4%bb%8e-php-7-4-%e5%8d%87%e7%ba%a7-8-4/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Sat, 26 Jul 2025 01:16:58 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[生活]]></category>
		<category><![CDATA[问题解决]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=6415</guid>

					<description><![CDATA[本博客站点用的是 WordPress，最近进入后台的时候，老 <a href="https://www.somedoc.net/2025/07/26/%e6%9c%ac%e7%ab%99%e4%bb%8e-php-7-4-%e5%8d%87%e7%ba%a7-8-4/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>本博客站点用的是 WordPress，最近进入后台的时候，老是提示使用的 PHP 7.4 版本太老，最好更新到 8 以上。老夫当然从善如流，立刻着手。</p>
<p>首先当然是加了个大众广泛使用的软件源（<code>LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php -y</code> 然后 <code>sudo apt update</code>），很可惜的是加完以后 apt 仍然报找不到更新版本的 PHP。<br />
​<br />
​又查了一下，哦豁，原来是 PHP 嫌弃操作系统 Ubuntu 18.04 太老，已经不再提供对应的安装包，不仅如此，而且看上去连 20.04 也已经被抛弃了。好吧，一步一步来。先升到 20.04 看看？出奇顺利，升级结束后立刻尝试访问博客，正常得不像话，就跟没有升级过一样。​胆子于是大了点。继续根据服务商的说明把 Ubuntu 从 20.04 往 22.04 上升。完成后先是感觉又很成功，系统启动正常。但随即尝试访问博客，呵呵，它就 502 了。事已至此，​先吃饭吧。</p>
<p>饭后继续。升级系统似乎把 PHP 7.4 有关的某些部分搞掉了，所以才 502。咱原本就是要升级 PHP 的，所以倒也不算什么大问题。于是当即再次执行前述的软件源添加命令，然后 <code>sudo apt install php8.4 php8.4-fpm php8.4-mcrypt php8.4-mysql php8.4-xml php8.4-zip</code>，好像就这些吧。然后去到 <code>/etc/php/8.4/fpm</code> 下，把 <code>pool.d/www.conf</code> 文件里的 <code>user</code>、<code>group</code> 以及 <code>listen.owner</code> 和 <code>listen.group</code> 修正成实际情况，<code>pm.max_requests</code> 稍微调了调；又打开 <code>php.ini</code> 把 <code>max_execution_time</code> 也调了下，最主要的还是 <code>post_max_size</code> 和 <code>upload_max_filesize</code> 这俩值，太小了不够用；最后看了一眼 <code>php-fpm.conf</code> 文件，发现什么都不需要动。执行 <code>sudo systemctl restart nginx php-fpm</code> 后尝试访问站点，嗯，502 消失了，代之以“此站点遇到了致命错误。”</p>
<p>页面相当干净，别的有用信息统统没有。只好去把 <code>wp-config.php</code> 里的 <code>WP_DEBUG</code> 开关打开，刷新页面。当即发现 crayon-syntax-highlighter 扩展可能是最重要的那个问题源（问题一），屏蔽了它再刷新，原来的正常页面内容就开始出现了，但夹杂着各种错误信息。就像泄洪一般，一大片的 Notice、Deprecated、Warning。</p>
<p>计有，页面顶部出现以下问题。问题二：</p>
<blockquote><p>Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the jalw_i18n domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /&#8230;/wp-includes/functions.php on line 6121</p></blockquote>
<p>查资料，此问题多由插件/主题带来。经测试，禁用 JS Archive List 插件后，此提示即告消失。在 AI 辅助下尝试修复未果。</p>
<p>接着是连续五条这个（问题三），</p>
<blockquote><p>Deprecated: Creation of dynamic property Hybrid_Layout::$name is deprecated in /&#8230;/wp-content/themes/stargazer/library/inc/class-layout.php on line 162</p></blockquote>
<p>这是一个本博客当前使用的主题，已久不更新。打开该文件，将以下成员声明放到类的开头，</p><pre class="crayon-plain-tag">/**
* The layout name/slug.
*
* @since 4.0.0
* @access public
* @var string
*/
public $name = '';</pre><p>即可解决（这是被第二个解决的问题，根由是 PHP 不再建议使用动态属性）。</p>
<p>还有一条是这样（问题四），</p>
<blockquote><p>Warning: foreach() argument must be of type array|object, string given in /&#8230;/wp-includes/class-wp-theme-json.php on line 2101</p></blockquote>
<p>不知道问题出在哪儿。</p>
<p>接下来是页面内出现最多的一组，总有十几次（问题五），</p>
<blockquote><p>Warning: compact(): Undefined variable $post_id in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $order in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $meta_key in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $featured in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $attachment in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $scan in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $scan_raw in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $callback in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $default in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $split_content in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $size in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $srcset_sizes in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $link in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $link_class in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $image_class in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $image_attr in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $width in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $height in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $before in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $after in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $min_width in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $min_height in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $caption in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $meta_key_save in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $thumbnail_id_save in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $cache in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $format in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $echo in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $custom_key in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $default_size in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $the_post_thumbnail in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $image_scan in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $default_image in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $order_of_image in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p>
<p>Warning: compact(): Undefined variable $link_to_post in /&#8230;/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298</p></blockquote>
<p>当我把第 298 行代码从 <code>$key = md5( serialize( compact( array_keys( $this-&gt;args ) ) ) );</code> 改为 <code>$key = md5( serialize( $this-&gt;args ) );</code> 后，这些警告消失。由于它太碍眼，所以是第一个被解决掉的。</p>
<p>上述共计五个问题，三和五已经解决掉，二和四未解决，不过它们仅是告警类信息，把 <code>WP_DEBUG</code> 关闭后是看不到的。第一个问题最严重，是那个代码高亮的插件引发，抽空了再看吧。</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2025/07/26/%e6%9c%ac%e7%ab%99%e4%bb%8e-php-7-4-%e5%8d%87%e7%ba%a7-8-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>支线任务</title>
		<link>https://www.somedoc.net/2025/03/31/%e6%94%af%e7%ba%bf%e4%bb%bb%e5%8a%a1/</link>
					<comments>https://www.somedoc.net/2025/03/31/%e6%94%af%e7%ba%bf%e4%bb%bb%e5%8a%a1/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Mon, 31 Mar 2025 02:46:13 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[图形图像]]></category>
		<category><![CDATA[问题解决]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=6351</guid>

					<description><![CDATA[工作中经常遇到这样的小烦恼，想要干一件事，做着做着，最后竟然 <a href="https://www.somedoc.net/2025/03/31/%e6%94%af%e7%ba%bf%e4%bb%bb%e5%8a%a1/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>工作中经常遇到这样的小烦恼，想要干一件事，做着做着，最后竟然把最开始的目标给忘记了。怪不得总书记教诲党员干部，要“不忘初心”。</p>
<p>昨天晚上，先是搞定一件许久之前就感觉应该改善的活儿，就是把小组件的大小从固定的尺寸改成能尽可能大地占据启动器给分配的空间。当中间那个主图变大后，又勾起了另一件之前想干的事，就是把这个主图搞成矢量图，避免缩放时候失真严重。</p>
<p>栅格图像转矢量图，有个效果不错的软件，叫 Vector Magic，多年前用过。到网上一搜，发现也出了在线版，网址给的是 https://zh.vectormagic.com/。打开页面一看，里面就有操作区，告诉只要把文件上传，就立等可取。依言而行，页面跳转到了一个编辑界面，左右两大内容栏并列，左侧是上传的栅格图像，右侧是转变后的矢量图像，果然边缘平滑，缩放自如。可这是你要是点击那个大大的“下载”按钮的话，它就会让你订阅，订阅的费用颇为不菲。嗐，你说这事闹得。</p>
<p>心里开始盘算，既然你已经显示到内容取了，有没有什么办法把内容区 dump 出来？初步检查了一下，内容区是个 Canvas 元素，于是就搜索 Canvas to SVG 的转换器，确实有，不过是供给网页制作者嵌入到页面里的。既然如此，就只好强行注入了。这种急就章是 AI 的强项，于是问 DeepSeek，几番来回，它给出了以下代码：</p><pre class="crayon-plain-tag">(function() {
    function loadScript(url) {
        return new Promise((resolve, reject) =&gt; {
            if (document.querySelector(`script[src="${url}"]`)) return resolve();
            const script = document.createElement('script');
            script.src = url;
            script.onload = resolve;
            script.onerror = reject;
            document.head.appendChild(script);
        });
    }

    async function exportCanvas(id) {
        const canvas = document.getElementById(id);
        if (!canvas) throw new Error('Canvas not found');
        
        await loadScript('https://unpkg.com/canvas2svg@1.0.16/canvas2svg.js');
        
        const ctx = new C2S(canvas.width, canvas.height);
        ctx.drawImage(canvas, 0, 0);
        
        const svgString = new XMLSerializer().serializeToString(ctx.getSvg());
        const blob = new Blob([svgString], {type: 'image/svg+xml'});
        
        const a = document.createElement('a');
        a.href = URL.createObjectURL(blob);
        a.download = `canvas-${id}-export.svg`;
        a.click();
        
        return '导出成功！';
    }

    // 使用示例：exportCanvas('yourCanvasId').then(console.log)
    window.exportCanvas = exportCanvas;
    console.log('使用方法：exportCanvas("你的Canvas元素ID")');
})();</pre><p>里面最重要的 JavaScript 库的 URL 它没给对，最后是自己找的。照着代码最后的提示说明操作，果然一个 SVG 文件顺利降落，用 Edge 打开一看，效果也对得上。时间太晚，满意地睡觉去了。</p>
<p>今早接茬往后走。定睛一看，SVG 没错，显示效果也没错，但是，这个 SVG 的体内是内嵌了一个栅格图像，SVG 这层外衣就是聋子的耳朵。衰。又下载 Vector Magic 的 Windows 试用版，心想免费让我转一半张图片总应该可以吧，没想到也是痴心妄想。跟网站一个德性，只能看，不能保存。又看了一眼正版价格，天啦噜，400 新加坡元，2000+ 人民币啊。溜了溜了。</p>
<p>这就怪不得老夫了，还是寻求破解版吧，于是找到了<a href="https://www.yxnet.net/943.html">这儿</a>，里面提供了百度网盘和蓝奏云的链接。一般来说蓝奏云比较省力气，就点了蓝奏云。发现需要登录，正要拿自己的账号登录时，看到一行小字，说这是蓝奏云优享版，账号跟之前的老蓝奏云不想通。好，那就新注册一个，反正现在一般用手机号接个验证码就算是注册用户了。验证通过后往下走，提示购买会员，要不然不能存到云盘，显然也不能下载。果断放弃。转战百度云盘，这边风景反而好起来了，挺顺利，转存后下载到本地。</p>
<p>解压，幺蛾子就来了。Defender 哐哐报毒。吓得老夫硬是没敢执行，心想得把沙盒开起来。到开始菜单里寻找，咦？之前经常看着都略显眼烦的沙盒没了！再到应用商店里找，也没有。奇了怪了，难道微软的刀法已经如此之快了？赶忙放狗，才在<a href="https://learn.microsoft.com/en-us/windows/security/application-security/application-isolation/windows-sandbox/windows-sandbox-install">微软官网</a>找到开启的办法：<code>Enable-WindowsOptionalFeature -FeatureName "Containers-DisposableClientVM" -All -Online</code>。原样运行完毕，嚓，提示要重启。忙不迭保存、关闭一大堆开着的窗口应用。重启电脑，打开沙盒，把破解版的程序跟图片都复制进去，一番炮制后，把成品又捞了出来，美滋滋。不过沙盒跟宿主机之间不能进行文件拖放操作，略有不便，好在复制粘贴还是可以工作的。</p>
<p>就这么一件小事，折腾不已。支线繁杂，令人头晕。幸好最后也算“牢记使命”，把活儿弄成了。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2025/03/31/%e6%94%af%e7%ba%bf%e4%bb%bb%e5%8a%a1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Cursor 答疑第二弹</title>
		<link>https://www.somedoc.net/2024/12/23/cursor-%e7%ad%94%e7%96%91%e7%ac%ac%e4%ba%8c%e5%bc%b9/</link>
					<comments>https://www.somedoc.net/2024/12/23/cursor-%e7%ad%94%e7%96%91%e7%ac%ac%e4%ba%8c%e5%bc%b9/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Mon, 23 Dec 2024 09:47:51 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[问题解决]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=6261</guid>

					<description><![CDATA[之前问过一次，今天又问了 Cursor 一个问题，记录一下。 <a href="https://www.somedoc.net/2024/12/23/cursor-%e7%ad%94%e7%96%91%e7%ac%ac%e4%ba%8c%e5%bc%b9/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>之前<a href="https://www.somedoc.net/2024/11/08/%e7%94%a8-cursor%ef%bc%8c%e5%be%97%e6%b0%b8%e7%94%9f/">问过一次</a>，今天又问了 Cursor 一个问题，记录一下。其实这些内容对于行家里手来说不值得一记，但俺是前端小白，就得记一下。</p>
<p>Q：在一个页面中需要展示一个图片，图片需要根据当前浏览器采用的语言而对应后端准备的不同资源，如何写最简单？</p>
<p>A：有几种简单的方法可以实现这个需求：</p>
<p>1. 使用 HTML 的 <span class="markdown-inline-code">lang</span> 属性和 CSS 选择器：</p><pre class="crayon-plain-tag">&lt;!-- 在 html 标签上设置语言 --&gt;
&lt;html lang="zh"&gt;
  &lt;body&gt;
    &lt;img class="language-image" src="default.png" alt="图片"&gt;
  &lt;/body&gt;
&lt;/html&gt;

&lt;style&gt;
/* CSS 中根据语言选择不同图片 */
:lang(zh) .language-image {
  content: url('/images/zh.png');
}
:lang(en) .language-image {
  content: url('/images/en.png');
}
&lt;/style&gt;</pre><p>2. 使用 JavaScript 检测浏览器语言：</p><pre class="crayon-plain-tag">&lt;img id="languageImage" src="" alt="图片"&gt;

&lt;script&gt;
const lang = navigator.language.slice(0, 2); // 获取语言代码前两位
const img = document.getElementById('languageImage');
img.src = `/images/${lang}.png`;
&lt;/script&gt;</pre><p>3. 使用 HTML 的 <span class="markdown-inline-code">picture</span> 元素：</p><pre class="crayon-plain-tag">&lt;picture&gt;
  &lt;source srcset="zh.png" media="(lang: zh)"&gt;
  &lt;source srcset="en.png" media="(lang: en)"&gt;
  &lt;img src="default.png" alt="图片"&gt;
&lt;/picture&gt;</pre><p><strong>推荐使用第 2 种方法，因为它最简单直接，且兼容性最好</strong>。</p>
<p>顺便说一句，虽说咱是个菜鸟，但问它的时候，就是想让它帮着写出来第 2 种方法的代码的，:)</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2024/12/23/cursor-%e7%ad%94%e7%96%91%e7%ac%ac%e4%ba%8c%e5%bc%b9/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>用 Cursor，得永生</title>
		<link>https://www.somedoc.net/2024/11/08/%e7%94%a8-cursor%ef%bc%8c%e5%be%97%e6%b0%b8%e7%94%9f/</link>
					<comments>https://www.somedoc.net/2024/11/08/%e7%94%a8-cursor%ef%bc%8c%e5%be%97%e6%b0%b8%e7%94%9f/#comments</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Fri, 08 Nov 2024 06:52:17 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[问题解决]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=6226</guid>

					<description><![CDATA[原来有个页面需求，就是在 iOS 上打开后，自动适应亮或者暗 <a href="https://www.somedoc.net/2024/11/08/%e7%94%a8-cursor%ef%bc%8c%e5%be%97%e6%b0%b8%e7%94%9f/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>原来有个页面需求，就是在 iOS 上打开后，自动适应亮或者暗主题模式。因为不是前端选手，所以当时就按下不表，直至这两天又想起来。然后想到正好可以问一下被人传的神乎其神的 Cursor。于是有了下面的记录。</p>
<p>Q：在一个 iOS app 中，要实现生成一个本地 HTML 页面，使用 WebView 显示出来。据我所知，手机目前都有明亮、暗黑两种模式，为了保证用户体验，HTML 页面应该能自动检测当前处于那种模式，并将适当的适应性 CSS 应用到页面元素上（如页面背景以及文字的颜色），可以帮助写一个简单的示例页面吗？</p>
<p>A：当然可以。以下是一个简单的示例 HTML 页面，它能够自动适应系统的明亮/暗黑模式：</p><pre class="crayon-plain-tag">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;自适应主题示例&lt;/title&gt;
    &lt;style&gt;
        /* 默认样式（明亮模式） */
        :root {
            color-scheme: light dark;
        }

        body {
            margin: 0;
            padding: 16px;
            background-color: #ffffff;
            color: #000000;
        }

        .card {
            padding: 16px;
            margin: 16px 0;
            border-radius: 8px;
            background-color: #f0f0f0;
            border: 1px solid #e0e0e0;
        }

        /* 暗黑模式样式 */
        @media (prefers-color-scheme: dark) {
            body {
                background-color: #000000;
                color: #ffffff;
            }

            .card {
                background-color: #1c1c1e;
                border-color: #2c2c2e;
            }

            a {
                color: #0a84ff;
            }
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;自适应主题示例&lt;/h1&gt;
    
    &lt;div class="card"&gt;
        &lt;h2&gt;示例卡片&lt;/h2&gt;
        &lt;p&gt;这是一个示例卡片，用于展示明暗模式的自动切换效果。&lt;/p&gt;
        &lt;p&gt;这里是一个 &lt;a href="#"&gt;链接&lt;/a&gt; 示例。&lt;/p&gt;
    &lt;/div&gt;

    &lt;div class="card"&gt;
        &lt;h2&gt;另一个卡片&lt;/h2&gt;
        &lt;p&gt;当系统切换到暗黑模式时，页面会自动调整颜色方案。&lt;/p&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p></p>
<section id="markdown-section-71ca3a80-5479-459c-9d70-57fde8e3dc47-4" class="markdown-section" data-markdown-raw="
这个示例页面的特点：" data-section-index="4">这个示例页面的特点：</section>
<section id="markdown-section-71ca3a80-5479-459c-9d70-57fde8e3dc47-6" class="markdown-section" data-markdown-raw="
1. 使用 &#96;color-scheme: light dark&#96; 告诉浏览器支持明暗两种模式。" data-section-index="6"></p>
<ol>
<li>使用 <code><span class="markdown-inline-code">color-scheme: light dark</code></span> 告诉浏览器支持明暗两种模式。</li>
<li>使用 <code><span class="markdown-inline-code">@media (prefers-color-scheme: dark)</code></span> 媒体查询来检测系统的暗黑模式。</li>
<li>为明暗两种模式分别定义了不同的：
<ol>
<li>背景色</li>
<li>文字颜色</li>
<li>卡片背景色和边框颜色</li>
<li>链接颜色</li>
</ol>
</li>
<li> 使用了一些基本的样式来美化页面：
<ol>
<li>卡片式布局</li>
<li>圆角边框</li>
<li>适当的内外边距</li>
</ol>
</li>
</ol>
</section>
<section id="markdown-section-71ca3a80-5479-459c-9d70-57fde8e3dc47-17" class="markdown-section" data-markdown-raw="
   - 卡片式布局" data-section-index="17"></section>
<section id="markdown-section-71ca3a80-5479-459c-9d70-57fde8e3dc47-18" class="markdown-section" data-markdown-raw="
   - 圆角边框" data-section-index="18"></p>
<div class="markdown-section-toolbar">
<div></div>
</div>
</section>
<section id="markdown-section-71ca3a80-5479-459c-9d70-57fde8e3dc47-19" class="markdown-section" data-markdown-raw="
   - 适当的内外边距" data-section-index="19"></p>
<div class="markdown-section-toolbar">
<div></div>
</div>
</section>
<section id="markdown-section-71ca3a80-5479-459c-9d70-57fde8e3dc47-21" class="markdown-section" data-markdown-raw="
当用户的系统在明暗模式之间切换时，页面会自动调整配色方案，无需刷新页面。" data-section-index="21"></p>
<div class="markdown-section-toolbar">
<div></div>
</div>
<p>当用户的系统在明暗模式之间切换时，页面会自动调整配色方案，无需刷新页面。</section>
<section class="markdown-section" data-markdown-raw="
当用户的系统在明暗模式之间切换时，页面会自动调整配色方案，无需刷新页面。" data-section-index="21">如果您需要在 iOS 中使用这个页面，可以将其保存为本地文件，然后使用 WKWebView 加载：</p><pre class="crayon-plain-tag">if let htmlPath = Bundle.main.path(forResource: "example", ofType: "html") {
    let url = URL(fileURLWithPath: htmlPath)
    let request = URLRequest(url: url)
    webView.load(request)
}</pre><p>您可以根据需要调整颜色、字体大小等样式，使其更好地匹配您的应用设计。</p>
<p>Q：明白了。我之前一直以为是要用 JavaScript 自行动态调整，没想到是用响应式样式，谢谢你！</p>
<p>A：是的！使用 CSS 的 <code><span class="markdown-inline-code">@media (prefers-color-scheme)</code></span> 媒体查询是一个更优雅的解决方案。它不仅代码更简洁，而且响应更快，因为：</p>
<section id="markdown-section-af2f76df-c5e4-4b10-a4ae-7fa6ba6559f3-4" class="markdown-section" data-markdown-raw="
1. 不需要运行 JavaScript 代码来检测和切换主题" data-section-index="4"></p>
<ol>
<li>不需要运行 JavaScript 代码来检测和切换主题</li>
<li>系统切换主题时会自动响应，不需要监听事件</li>
<li>即使禁用了 JavaScript，主题切换依然可以工作</li>
<li>页面加载时就能直接应用正确的主题，不会出现闪烁</li>
</ol>
<p>不过，如果您确实需要在 JavaScript 中检测当前主题（比如需要根据主题做一些其他处理），也可以使用：</p><pre class="crayon-plain-tag">if (window.matchMedia &amp;&amp; window.matchMedia('(prefers-color-scheme: dark)').matches) {
    // 当前是暗黑模式
}

// 监听主题变化
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event =&gt; {
    if (event.matches) {
        // 切换到暗黑模式
    } else {
        // 切换到明亮模式
    }
});</pre><p>但在大多数情况下，仅使用 CSS 媒体查询就足够了！</p>
</section>
</section>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2024/11/08/%e7%94%a8-cursor%ef%bc%8c%e5%be%97%e6%b0%b8%e7%94%9f/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>[转] 如何设定网站的 favicon</title>
		<link>https://www.somedoc.net/2023/11/30/%e8%bd%ac-%e5%a6%82%e4%bd%95%e8%ae%be%e5%ae%9a%e7%bd%91%e7%ab%99%e7%9a%84-favicon/</link>
					<comments>https://www.somedoc.net/2023/11/30/%e8%bd%ac-%e5%a6%82%e4%bd%95%e8%ae%be%e5%ae%9a%e7%bd%91%e7%ab%99%e7%9a%84-favicon/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Thu, 30 Nov 2023 08:45:03 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[技术]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=5792</guid>

					<description><![CDATA[favicon 是一个用来帮助用户标识网站的小图标，比如百度 <a href="https://www.somedoc.net/2023/11/30/%e8%bd%ac-%e5%a6%82%e4%bd%95%e8%ae%be%e5%ae%9a%e7%bd%91%e7%ab%99%e7%9a%84-favicon/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>favicon 是一个用来帮助用户标识网站的小图标，比如百度用熊掌、谷歌用大写的『G』，几乎每个网站都有。通常企业、组织或者个人建设网站时，都会有品牌设计，这个 favicon 小图片也是品牌设计中 logo 的一部分，一般是品牌 logo 的变种或者是缩小版。</p>
<p>那么如何为你的网站添加这个可爱的 favicon 呢？</p>
<p>注：本文涉及内容：</p>
<ul>
<li>图标大小尺寸</li>
<li>在网页上添加图标标识</li>
<li>不讨论如何设计精美图标</li>
</ul>
<h2 id="favicon-的用途" class="relative group">favicon 的用途</h2>
<p>在介绍如何为网页设置 favicon 之前，先来看看这些图标被用到了哪些地方。</p>
<ul>
<li>浏览器标签图标</li>
<li>浏览器书签图标</li>
<li>浏览器历史记录图标</li>
<li>浏览器中的快捷启动图标</li>
<li>手机上的快捷启动图标</li>
<li>任务栏图标</li>
</ul>
<p>&nbsp;</p>
<figure><img fetchpriority="high" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/example.webp" alt="示例：火狐中的网站图标" width="2326" height="1234" /><figcaption class="text-center">示例：火狐中的网站图标</figcaption></figure>
<p>&nbsp;</p>
<h2 id="favicon-图标的格式" class="relative group">favicon 图标的格式</h2>
<p>favicon 是由微软在 1980 年代设计出来的，最原始只支持 16×16 像素的图片，后来被用到 IE5 上标识书签和网站，并且扩展到一个 ico 图标文件中可以包含 32×32、 24×24、48×48、64×64、128×128、256×256 等多种尺寸的图片。</p>
<p>在现代浏览器上，可以直接使用 <em>gif</em>、<em>png</em> 等格式作为 favicon，而无须再转为 <em>ico</em> 格式。</p>
<p>一个 favicon.ico 就可以包含多尺寸图片，那还有什么好讨论的呢？的确是个好问题。后面问答。</p>
<h2 id="如何引用这个-favicon-图标" class="relative group">如何引用这个 favicon 图标</h2>
<p>在你的图站根目录放上一个名为 
			<span id="crayon-68a148e7c8954240993671" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">favicon</span><span class="crayon-sy">.</span><span class="crayon-v">ico</span></span></span> 的符合规范的 ico 图片文件，即可。浏览器会使用 <em>http(s)://你的网站地址/favicon.ico</em> 来获取这个图标。</p>
<p>到后来，在 html 标准里，为 favicon 设计了规范。在 html 文档的 head 部，通过 
			<span id="crayon-68a148e7c8959428102248" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">&lt;</span><span class="crayon-v">link</span><span class="crayon-o">&gt;</span></span></span>来声明图标位置。</p><pre class="crayon-plain-tag">&lt;link rel="icon" type="image/x-icon" href="/favicon.ico"&gt;
&lt;link rel="icon" href="/favicon.ico"&gt;
&lt;link rel="icon" type="image/gif" href="/favicon.gif"&gt;
&lt;link rel="icon" type="image/png" href="/favicon.png"&gt;</pre><p>在现在常用的浏览器，以上的图标地址声明均可以产生作用，如果没有通过 
			<span id="crayon-68a148e7c895c259432835" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">&lt;</span><span class="crayon-v">link</span><span class="crayon-o">&gt;</span></span></span> 声明图标地址，浏览器会使用默认的 <em>http(s)://你的网站地址/favicon.ico</em> 来获取。</p>
<p>如果你不知道什么叫 <em>Progressive Web App</em>，请忽略本段，继续下一节。</p>
<p>若你的网站是 <em>Progressive Web App</em> 应用，此时页面的 head 部很可能会 
			<span id="crayon-68a148e7c895e221659421" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">link</span></span></span> 名为 <em>manifest.json</em> 的文件，这个文件有 <a href="https://www.w3.org/TR/appmanifest/" target="_blank" rel="external nofollow noopener noreferrer">W3C 标准 </a>，其中 
			<span id="crayon-68a148e7c895f138318537" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">icons</span></span></span>、
			<span id="crayon-68a148e7c8960420133266" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">splash_screens</span></span></span> 两项配置与图标相关，内容大致为：</p><pre class="crayon-plain-tag">{
  "lang": "zh—CN",
  "name": "今日 | 有悟 | 有物",
  "short_name": "今日有物",
  "icons": [],
  "splash_screens": [],
  "scope": "/",
  "start_url": "",
  "display": "fullscreen",
  "orientation": "landscape",
  "theme_color": "aliceblue",
  "background_color": "red"
}</pre><p></p><pre class="crayon-plain-tag">&lt;link rel="manifest" href="/manifest.json"&gt;&lt;/link&gt;</pre><p></p>
<h2 id="那么多地方引用 favicon 如何选择合适的尺寸" class="relative group">那么多地方引用 favicon，如何选择合适的尺寸</h2>
<p>考虑安卓、苹果的手机与平板等移动设备以及桌面设备，以及现代屏幕的物理像素，问题终于来了，这么多的地方引用到网站图标，哪一个尺寸大小的图标才是你需要的？</p>
<p>你可能有过这种经历：某种工具或者网站在桌面上的快捷方式图标被拉伸成一堆小方格了。这是由于图标分辨率太低，无法在分辨率更高的屏幕上正常显示。</p>
<p>网站快捷启动图标或 app 的图标需要清晰度更高、符合浏览设备屏幕分辨率的高质量图片。在浏览器中作为书签使用，与在手机桌面作为快捷启动图标，与在电脑桌面快捷启动，在不同的物理屏幕分辨率屏幕、不同的操作系统都有不同的最佳图标尺寸要求。把这么多的需求一起打包成一个 ico 格式文件明显不合适（这也回答了上面文中所留的一个问题）。通过使用 
			<span id="crayon-68a148e7c8965856107582" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">&lt;</span><span class="crayon-v">link</span><span class="crayon-o">&gt;</span></span></span> 和 <em>manifest.json</em>，开发人员可以控制在不同操作系统不同分辨率要求下的桌面快捷启动图标、浏览器 favicon。</p>
<blockquote><p><strong>特别说明</strong>： 因为设备与浏览器的升级，导致这些图标尺寸也在不断变化，以下所引文章是当前（2021 年 6 月）最新情况。太老的设备或者即将退役（如 ie）版本不在本文考虑范围。可能与你之前阅读过的与图标尺寸选择相关的文章会有出入。</p></blockquote>
<h3 id="chrome-浏览器图标大小" class="relative group">Chrome 浏览器图标大小</h3>
<p>google 推荐，为充分支持所有浏览器， <a href="https://developers.google.com/web/fundamentals/design-and-ux/browser-customization/#%E6%8F%90%E4%BE%9B%E5%87%BA%E8%89%B2%E7%9A%84%E5%9B%BE%E6%A0%87%E5%92%8C%E7%A3%81%E8%B4%B4" target="_blank" rel="external nofollow noopener noreferrer">使用最高的 192×192 分辨率 icon</a>。chrome 和 opera 均使用 
			<span id="crayon-68a148e7c8966689293600" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">icon</span><span class="crayon-sy">.</span><span class="crayon-v">png</span></span></span>，图标会被自动缩放到设备所需大小。</p><pre class="crayon-plain-tag">&lt;link rel="icon" sizes="192x192" href="icon.png"&gt;</pre><p></p>
<blockquote><p>图标大小应基于 48px，例如 48px、96px、144px 和 192px。另外，google web 开发还针对在移动设备上的 <a href="https://web.dev/add-manifest/#splash-screen" target="_blank" rel="external nofollow noopener noreferrer">Splash 画面 </a>（启动时显示的图片而不是白屏）给出以下尺寸建议，192px 与 512px 已经满足大部分场景，但你可以为了像素调整提供更多的选项，比如 256px、384px。</p></blockquote>
<p></p><pre class="crayon-plain-tag">&lt;link rel="icon" sizes="48x48" href="icon-48.png"&gt;
&lt;link rel="icon" sizes="96x96" href="icon-96.png"&gt;
&lt;link rel="icon" sizes="144x144" href="icon-144.png"&gt;
&lt;link rel="icon" sizes="192x192" href="icon-192.png"&gt;
&lt;link rel="icon" sizes="256x256" href="icon-256.png"&gt;
&lt;link rel="icon" sizes="384x384" href="icon-384.png"&gt;
&lt;link rel="icon" sizes="512x512" href="icon-512.png"&gt;</pre><p></p>
<h3 id="safari-浏览器的图标尺寸" class="relative group">Safari 浏览器的图标尺寸</h3>
<p>而 apple 对浏览器与应用的图标尺寸 <a href="https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/#app-icon-sizes" target="_blank" rel="external nofollow noopener noreferrer">推荐建议</a>：</p>
<ul>
<li>iPhone： 60&#215;60 pt (180&#215;180 px @3x) 60&#215;60 pt (120&#215;120 px @2x)</li>
<li>iPad Pro： 83.5&#215;83.5 pt (167&#215;167 px @2x)</li>
<li>iPad, iPad mini： 76&#215;76 pt (152&#215;152 px @2x)</li>
</ul>
<p>
			<span id="crayon-68a148e7c896a952570159" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">@</span><span class="crayon-cn">2x</span></span></span> 与 
			<span id="crayon-68a148e7c896c311642127" class="crayon-syntax crayon-syntax-inline  crayon-theme-visual-assist crayon-theme-visual-assist-inline crayon-font-droid-sans-mono" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important;"><span class="crayon-pre crayon-code" style="font-size: 13px !important; line-height: 16px !important;font-size: 13px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">@</span><span class="crayon-cn">3x</span></span></span> 是 apple 特有，主要是 retina 屏幕，使用两倍大小或者三倍大小，图标会更清晰。</p><pre class="crayon-plain-tag">&lt;link rel="apple-touch-icon" sizes="120x120" href="apple-touch-icon-120.png"&gt;
&lt;link rel="apple-touch-icon" sizes="152x152" href="apple-touch-icon-152.png"&gt;
&lt;link rel="apple-touch-icon" sizes="167x167" href="apple-touch-icon-167.png"&gt;
&lt;link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon-180.png"&gt;</pre><p></p>
<h3 id="合并以上所有提到的图标尺寸" class="relative group">合并以上所有提到的图标尺寸</h3>
<ul>
<li>favicon.ico</li>
<li>favicon-16.png</li>
<li>favicon-32.png</li>
<li>icon-48.png</li>
<li>icon-96.png</li>
<li>icon-144.png</li>
<li>icon-192.png</li>
<li>icon-256.png</li>
<li>icon-384.png</li>
<li>icon-512.png</li>
<li>apple-touch-icon-120.png</li>
<li>apple-touch-icon-152.png</li>
<li>apple-touch-icon-167.png</li>
<li>apple-touch-icon-180.png</li>
</ul>
<p>html 头的 link 声明：</p><pre class="crayon-plain-tag">&lt;link rel="icon" type="iamge/png" sizes="16x16" href="favicon-16.png"&gt;
&lt;link rel="icon" type="iamge/png" sizes="32x32" href="favicon-32.png"&gt;
&lt;link rel="icon" sizes="48x48" href="icon-48.png"&gt;
&lt;link rel="icon" sizes="96x96" href="icon-96.png"&gt;
&lt;link rel="icon" sizes="144x144" href="icon-144.png"&gt;
&lt;link rel="icon" sizes="192x192" href="icon-192.png"&gt;
&lt;link rel="icon" sizes="256x256" href="icon-256.png"&gt;
&lt;link rel="icon" sizes="384x384" href="icon-384.png"&gt;
&lt;link rel="icon" sizes="512x512" href="icon-512.png"&gt;
&lt;link rel="apple-touch-icon" sizes="120x120" href="apple-touch-icon-120.png"&gt;
&lt;link rel="apple-touch-icon" sizes="152x152" href="apple-touch-icon-152.png"&gt;
&lt;link rel="apple-touch-icon" sizes="167x167" href="apple-touch-icon-167.png"&gt;
&lt;link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon-180.png"&gt;
&lt;link rel="manifest" href="manifest.json"&gt;</pre><p>这个图标文件无须声明，要直接放在网站根目录下。</p>
<h2 id="上面所列图标的尺寸都需要吗" class="relative group">上面所列图标的尺寸都需要吗？</h2>
<p>在回答这个问题之前，先来看有悟所做的测试。有悟制作了一套图标，并标上尺寸数字，找了几款设备做不完全的测试，看看到底这些尺寸都被用到哪些？</p>
<figure><img decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/ipad-chrome.webp" alt="ipad chrome 浏览器" width="1536" height="1488" /><figcaption class="text-center">iPad Chrome 浏览器</figcaption></figure>
<figure><img decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/ipad-homescreen.webp" alt="ipad 主屏幕" width="1536" height="468" /><figcaption class="text-center">iPad 主屏幕</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/ipad-safari.webp" alt="ipad safari浏览器" width="1536" height="571" /><figcaption class="text-center">iPad Safari浏览器</figcaption></figure>
<p>&nbsp;</p>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/iphone-homescreen-addto.webp" alt="iphone 添加到屏幕" width="750" height="530" /><figcaption class="text-center">iPhone 添加到屏幕</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/iphone-homescreen.webp" alt="iphone 主屏幕" width="750" height="298" /><figcaption class="text-center">iPhone 主屏幕</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/iphone-safari.webp" alt="iphone safari浏览器" width="750" height="614" /><figcaption class="text-center">iPhone Safari 浏览器</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/iphone-safari-bookmark.webp" alt="safari浏览器书签" width="750" height="1334" /><figcaption class="text-center">Safari 浏览器书签</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/iphone-wechat.webp" alt="微信" width="750" height="1334" /><figcaption class="text-center">微信</figcaption></figure>
<p>&nbsp;</p>
<p>&nbsp;</p>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/mac-chrome.webp" alt="mac chrome浏览器" width="1454" height="974" /><figcaption class="text-center">macOS Chrome 浏览器</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/mac-firefox.webp" alt="mac 火狐浏览器" width="1554" height="1250" /><figcaption class="text-center">macOS 火狐浏览器</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/mac-safari.webp" alt="mac safari浏览器" width="1818" height="892" /><figcaption class="text-center">macOS Safari 浏览器</figcaption></figure>
<figure><img loading="lazy" decoding="async" class="mx-auto my-0 rounded-md" src="https://youwu.today/skill/web/how-to-favicon-your-web-site/mac-safari-bookmark.webp" alt="mac safari浏览器书签" width="1816" height="810" /><figcaption class="text-center">macOS Safari 浏览器书签</figcaption></figure>
<p>&nbsp;</p>
<table>
<thead>
<tr>
<th></th>
<th>macOS 11.4</th>
<th>iPhone iOS 14.6</th>
<th>iPad iOS 14.6</th>
</tr>
</thead>
<tbody>
<tr>
<td>火狐标签</td>
<td>16&#215;16</td>
<td></td>
<td></td>
</tr>
<tr>
<td>火狐快捷方式</td>
<td>512&#215;512</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Chorme</td>
<td>32&#215;32</td>
<td></td>
<td>144&#215;144</td>
</tr>
<tr>
<td>Safari 标签</td>
<td>32&#215;32</td>
<td></td>
<td>32&#215;32</td>
</tr>
<tr>
<td>Safari 快捷方式</td>
<td>180&#215;180</td>
<td>180&#215;180</td>
<td></td>
</tr>
<tr>
<td>Home Screen</td>
<td></td>
<td>120&#215;120</td>
<td>152&#215;152</td>
</tr>
<tr>
<td>微信</td>
<td></td>
<td>120&#215;120</td>
<td>120&#215;120</td>
</tr>
</tbody>
</table>
<p>因为浏览器会自动为我们缩小图标，那么可以利用这个功能，将上面的尺寸做精简后合并成一个比较大的 ico 文件，基本上大部分情况都可以覆盖。但是你如果要针对不同尺寸作出更精确的控制，比较大图标多内容、小图标仅图案，还是建议你分开图标文件分别定制，用 <em>html head link</em> 的方式来引用。</p>
<p>一个最少图标文件尺寸的集合：</p>
<ul>
<li>favicon.ico ( 16×16, 32×32 )</li>
<li>favicon-16.png</li>
<li>favicon-32.png: Safari</li>
<li>apple-touch-icon.png: Apple touch icon，180&#215;180</li>
<li>icon-192.png: Chrome 浏览器，安卓平台</li>
</ul>
<p><em>html head</em>：</p><pre class="crayon-plain-tag">&lt;link rel="icon" type="iamge/png" sizes="16x16" href="favicon-16.png"&gt;
&lt;link rel="icon" type="iamge/png" sizes="32x32" href="favicon-32.png"&gt;
&lt;link rel="icon" sizes="192x192" href="icon-192.png"&gt;
&lt;link rel="apple-touch-icon" href="apple-touch-icon.png"&gt;</pre><p>如果你的网站是 <em>Progressive Web App</em>，有配置文件 <em>manifest.json</em>，</p><pre class="crayon-plain-tag">&lt;link rel="manifest" href="manifest.json"&gt;</pre><p>内容类似如下:</p><pre class="crayon-plain-tag">{
  "lang": "zh—CN",
  "name": "今日 | 有悟 | 有物",
  "short_name": "今日有物",
  "icons": [
    {
      "src": "/icon-192.png",
      "sizes": "192x192",
      "type": "image/png"
     }
  ],
  "splash_screens": [],
  "scope": "/",
  "start_url": "",
  "display": "fullscreen",
  "orientation": "landscape",
  "theme_color": "aliceblue",
  "background_color": "red"
}</pre><p>上面已经把全尺寸覆盖，最小化两种方案都介绍完毕。不过，如果你知道了图片可以快速生成，那即使采用全覆盖方案，对你来说根本不会产生什么负担。 因为，若图标都是用工具自动生成的话，根本不用在乎多少个尺寸型号，对于工具来说，只是大小参数不同而已。</p>
<p>为了控制本文的篇幅，避免篇幅过长造成阅读困难，关于如果快速制作 favicon 文件的方法，请看：<a href="https://youwu.today/blog/how-to-create-multiple-sizes-favicon-quickly-and-for-free/">如何快速制作多尺寸 favicon</a>。</p>
<p>参考文章：<a href="https://mobiforge.com/design-development/adding-favicons-in-a-multi-browser-multi-platform-world" target="_blank" rel="external nofollow noopener noreferrer">Adding favicons in a multi-browser multi-platform world </a></p>
<p>原文链接：https://youwu.today/skill/web/how-to-favicon-your-web-site/</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2023/11/30/%e8%bd%ac-%e5%a6%82%e4%bd%95%e8%ae%be%e5%ae%9a%e7%bd%91%e7%ab%99%e7%9a%84-favicon/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>老年筋骨</title>
		<link>https://www.somedoc.net/2023/11/29/%e8%80%81%e5%b9%b4%e7%ad%8b%e9%aa%a8/</link>
					<comments>https://www.somedoc.net/2023/11/29/%e8%80%81%e5%b9%b4%e7%ad%8b%e9%aa%a8/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Wed, 29 Nov 2023 10:58:09 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[生活]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=5790</guid>

					<description><![CDATA[双人正哥尝语于予言，年老不以筋骨为能。 老夫虽然编程多年（当 <a href="https://www.somedoc.net/2023/11/29/%e8%80%81%e5%b9%b4%e7%ad%8b%e9%aa%a8/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>双人正哥尝语于予言，年老不以筋骨为能。</p>
<p>老夫虽然编程多年（当然现在还可以说不编程也多年），但对于前端的知识一直处于一知半解的状态，偶尔突击一下，不几天就会全额返还，说不定还带了利息。之前的门户站就是为了备案而写就的一个页面，好听点说是简洁，不好听的说就是简陋，这一晃就两年多了，老夫决定上手改一版。</p>
<p>这一改，总怕是改了两个礼拜，说不定还更长。找目标模板、扒下来，整理。改内容，改样式，找图片，然后测试调整。尤其是找图标、图片，甚至还要处理它们，什么裁剪放缩，甚至还要搞 SVG。终于今天算是把修改后的主页上线了，效果肯定不敢说多好，不过对老夫来说，肯定是可以接受的了。</p>
<p>这期间，扩展了一下 HTML 的知识，学习了一些 CSS 知识，JavaScript 还没动。主页上有个下拉的导航菜单，由于模板找的是十年前的，技术栈显然会比较老，下拉菜单是用 JavaScript 脚本驱动的，老夫计划挑战一下前段时间的学习成果，用纯 CSS 把它替换掉。学习的目标已经找到了一些，列在这儿。</p>
<ul>
<li>https://preview.colorlib.com/theme/bootstrap/dropdown-20/；这个菜单样式还行，不过需要点击后才拉下；这个站的 www 主站好像是个 WordPress 主题站，抽空可以多看看；</li>
<li>https://purecss.io/menus/；这个页面演示了若干种用 CSS 实现的菜单，不止下拉式，不过相对简单；</li>
<li>https://codeconvey.com/Tutorials/pure-css-responsive-drop-down-menu/；这个页面的菜单，样式是我认可的，不过它的实现有个在网上常常遇到的 bug，就是鼠标指针从顶级菜单向下拉菜单滑动时，一旦离开顶级菜单项的范围，有概率会导致下拉菜单突然消失，这对于用户是非常不友好的；留在此处就是为了有时间看看究竟是什么地方考虑失当导致的；</li>
<li>https://1stwebdesigner.com/pure-css-navigation-menus/；这个页面里也罗列了不止一种实现，其中的 Mega Menu 是我的目标，预览页地址是 <a href="https://codepen.io/mohnaji94/pen/evbWGW">https://codepen.io/mohnaji94/pen/evbWGW</a>；看上去实现很简洁，效果也符合预期。</li>
</ul>
<p>昨天还和 BOSS 直聘上打招呼的一位仁兄见了个面，他的岁数跟刚刚分别的老歪一样，八月份在原公司因业务被砍而失去工作，这数个月来，甚至连面试机会都接近于无。据他说只有一次，我都没好意思追问是不是就是我这一次。在技能上，大概率界面方面还是需要精进的，不过感觉基本功还应该可以，给他聊了个小测试的活儿，看看这一两天的反馈。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2023/11/29/%e8%80%81%e5%b9%b4%e7%ad%8b%e9%aa%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>烟花特效</title>
		<link>https://www.somedoc.net/2023/09/26/%e7%83%9f%e8%8a%b1%e7%89%b9%e6%95%88/</link>
					<comments>https://www.somedoc.net/2023/09/26/%e7%83%9f%e8%8a%b1%e7%89%b9%e6%95%88/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Tue, 26 Sep 2023 08:30:07 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[备忘录]]></category>
		<category><![CDATA[技术]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=5694</guid>

					<description><![CDATA[有时候计划在项目里展示一个放烟花/礼花的特效，没看到 And <a href="https://www.somedoc.net/2023/09/26/%e7%83%9f%e8%8a%b1%e7%89%b9%e6%95%88/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>有时候计划在项目里展示一个放烟花/礼花的特效，没看到 Android 下有现成实现的好看的，倒是 Web 上有，最开始是找到了 <a href="https://fireworks.nianbroken.top/">烟花模拟器 (nianbroken.top)</a> 这个站点，后来才发现，应该就是 https://codepen.io/MillerTime/pen/XgpNwb 这个项目。</p>
<p>有时间了看如何移植到 Android 上。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2023/09/26/%e7%83%9f%e8%8a%b1%e7%89%b9%e6%95%88/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>App logo 白嫖录</title>
		<link>https://www.somedoc.net/2023/09/22/app-logo-%e7%99%bd%e5%ab%96%e5%bd%95/</link>
					<comments>https://www.somedoc.net/2023/09/22/app-logo-%e7%99%bd%e5%ab%96%e5%bd%95/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Fri, 22 Sep 2023 10:31:18 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[软件]]></category>
		<category><![CDATA[问题解决]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=5685</guid>

					<description><![CDATA[作为一个只会写点代码的程序员，现在连给 app 设计一个 l <a href="https://www.somedoc.net/2023/09/22/app-logo-%e7%99%bd%e5%ab%96%e5%bd%95/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>作为一个只会写点代码的程序员，现在连给 app 设计一个 logo 都是难事。复杂的设计软件吧，不会用，只好到线上找那种傻瓜式的设计站，然而呢，又时常被晃点。</p>
<p>有一个网站，好像叫 BrandCrowd，打着免费的名义注册，在里面划拉过来划拉过去，好不容弄出个勉强还能交代得了自己眼睛的东西，说保存下来吧，嚓，狗日的要你订阅套餐。否则的话，页面上显示着那个打着水印的你的半吊子心血在那儿引诱你。</p>
<p>有个站还不错，支持免费下载，是这个：https://www.shopify.com/tools/logo-maker。虽然是 Shopify 的 URL，可是这个工具又管自己叫 Hatchful，不知道什么由来。再次，弄了个凑合着能看的，点击下载按钮。站点非常友好地提示，说真正的下载 URL 已经发到注册邮箱，请自取。事实上从这儿开始才是坑。老夫从邮箱邮件里的 URL 点击下载，总不下二十次，每回都是确实给你返回一个压缩包文件，但是打开的话，里面是空的。还生怕压缩包兼容性不好，到资源浏览器里看了一眼，立马心就凉了，这个压缩包才 22 个字节，顶多也就是个压缩文件头，哪里会有什么内容。于是情况变得跟第一种就没什么区别了。</p>
<p>接着开始动脑筋。检查了一下第一个的页面，发现图案绘制在 <code>Canvas</code> 元素中，于是就寻找能直接把运行着的浏览器的页面里的 Canvas 元素转储成图片（最好是矢量的）的方法，几天未果；后来无意看了一下第二个的页面，嗐，好像有点进步，这个页面是最后的综述页，里面的图案已经不在编辑器里了，所以呈现使用的是 <code>svg</code> 元素。老夫把浏览器自带的开发工具打开，定位到 svg 元素上，把 outerHTML 转头复制存储成了一个 .svg 文件，就成了。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2023/09/22/app-logo-%e7%99%bd%e5%ab%96%e5%bd%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>被动了解的 JavaScript 凌乱知识</title>
		<link>https://www.somedoc.net/2022/06/27/%e8%a2%ab%e5%8a%a8%e4%ba%86%e8%a7%a3%e7%9a%84-javascript-%e5%87%8c%e4%b9%b1%e7%9f%a5%e8%af%86/</link>
					<comments>https://www.somedoc.net/2022/06/27/%e8%a2%ab%e5%8a%a8%e4%ba%86%e8%a7%a3%e7%9a%84-javascript-%e5%87%8c%e4%b9%b1%e7%9f%a5%e8%af%86/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Mon, 27 Jun 2022 07:34:32 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[技术]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=5063</guid>

					<description><![CDATA[之前对一个项目有兴趣，里面的前端框架使用了 Vue2，然而本 <a href="https://www.somedoc.net/2022/06/27/%e8%a2%ab%e5%8a%a8%e4%ba%86%e8%a7%a3%e7%9a%84-javascript-%e5%87%8c%e4%b9%b1%e7%9f%a5%e8%af%86/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>之前对一个项目有兴趣，里面的前端框架使用了 Vue2，然而本地测试部署的时候，包管理器会报告大量的风险，于是就想着把它更新到 Vue3。不曾想这是遇到了 Vue 升级史上的高级别难度关卡，从基础层面就会有大量的不兼容。为了把自己的踏出来的第一步推进下去，要查阅挺多信息，然而在打开若干标签页之后，终于还是把时间又让给了其它的事情。然后，就又到了要清理标签页的时候了，为了不让先前的过程白费，尽可能在这里留下一些摘抄、记录、感想等等的痕迹。</p>
<p>感受 Vue3 跟 Vue2 不一样的第一个重量冲击来自于事件总线机制发生了变化。</p>
<p>在 Vue2 里面，各种操作的简略表达如下：</p>
<ol>
<li><code>Vue.prototype.$bus=new Vue()</code></li>
<li>监听： <code>this.$bus.$on(‘方法名', (参数)=&gt;{})</code>，它可以累加</li>
<li>触发： <code>this.$bus.$emit(‘方法名', 实参值)</code></li>
<li>销毁：<code>this.$bus.$off(‘方法名')</code>，谁监听谁销毁</li>
<li>注意： 由于监听可以累加，所以必须要有第 4 步的销毁</li>
</ol>
<p>到了 Vue3 里面，通常要借助于额外 npm 的组件 <code>tiny-emitter</code> 或者 <code>mitt</code> 来通讯，网上看尤以后者居多。如果是前者，则用法基本上如，</p><pre class="crayon-plain-tag">import emitter from ‘tiny-emitter/instance'
import {onMounted} from ‘vue'

setup(){
       onMounted(()=&gt;{
            emitter.on('监听的方法名', (参数)=&gt;{回调函数}) // 监听
            emitter.emit('监听的方法名', 参数)             // 触发
            emitter.off('监听的方法名', 参数)              // 销毁
       }) 
}</pre><p>如果是后者，则如，</p><pre class="crayon-plain-tag">import mitt from ‘mitt'

bus.on('监听的方法名', (参数)=&gt;{回调函数}) // 监听
bus.emit('监听的方法名', 参数)             // 触发
bus.off('监听的方法名', 参数)              // 销毁</pre><p>举例如，首先在 <code>main.js</code> 注册，</p><pre class="crayon-plain-tag">import mitt from 'mitt'

const $bus = {}
const emitter = mitt()

$bus.on = emitter.on
$bus.emit = emitter.emit
$bus.off = emitter.off

app.config.globalProperties.$bus = $bus
app.mount('#app')</pre><p>在事件接收的页面里写，</p><pre class="crayon-plain-tag">import {getCurrentInstance, onUnmounted} from 'vue'

setup() {
    const $bus = getCurrentInstance().appContext.config.globalProperties.$bus

    $bus.on('eventName', options =&gt; {
        // 自定义业务
    })

    // 清除监听
    onUnmounted(() =&gt; {
        $bus.off('eventName')
    })
}</pre><p>在事件发送的页面里写，</p><pre class="crayon-plain-tag">import {getCurrentInstance} from 'vue

setup() {
    const $bus = getCurrentInstance().appContext.config.globalProperties.$bus

    let params = {a: 123} // 自定义数据
    $bus.emit('eventName', params)
}</pre><p>以上为简略版的示意。参考链接如下：</p>
<p>&#8211; https://www.jb51.net/article/223798.htm<br />
&#8211; https://blog.csdn.net/qq_41577134/article/details/119956038</p>
<p>还有更详细的一篇是《vue2 升级至 vue3  项目技术栈升级攻略》，讲述从 Vue2 到 Vue3 的基本迁移步骤。</p>
<p>首先是依赖层面 <code>package.json</code> 更新版本依赖，</p><pre class="crayon-plain-tag">{
  "name": "myApp",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint --no-fix"
  },
  "dependencies": {
    "element-plus": "^1.1.0-beta.9",
    "vue": "^3.2.9",
    "vue-router": "^4.0.11",
    "vuex": "^4.0.2"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "vue-template-compiler": "^2.6.14"
  }
}</pre><p>然后在代码层面，依次，</p>
<p>1）<code>new Vue()</code> 改写为 <code>createApp()</code>。因为 vue2 使用 <code>new Vue()</code> 创建 vue 实例，vue3 通过 <code>createApp()</code> 创造实例。</p><pre class="crayon-plain-tag">// vue2
import Vue from 'vue';
new Vue({
  render: h =&gt; h(App)
}).$mount("#app");

// 修改为：

// vue3
import { createApp } from 'vue';
import App from "./App.vue";
const app =  createApp(App);
app.mount('#app');</pre><p>2) <code>Vue.prototype</code> 改写为 <code>app.config.globalProperties</code></p>
<p>3）<code>Vue.extend</code> 废弃，如果要拓展组件要使用 <code>extends</code> 属性</p>
<p>4）Vue 全局方法改写为实例的方法</p>
<p>5）<code>filter</code> 弃用，可以通过 <code>compute</code> 定义函数代替；如果是全局定义的 <code>filter</code> 方法，可以通过定义 <code>filter</code> 全局常量来代替</p>
<p>6）event bus 废弃，可自行实现一个 event bus 封装</p><pre class="crayon-plain-tag">class Bus {
    constructor() {
    // 收集订阅，调度中心
        this.list = {};
    }
    // 订阅
    $on(name, fn) {
        this.list[name] = this.list[name] || [];
        this.list[name].push(fn);
    }
    // 发布
    $emit(name, data) {
        if (this.list[name]) {
            this.list[name].forEach((fn) =&gt; {
                fn(data);
            });
        }
    }

    // 取消订阅
    $off(name) {
        if (this.list[name]) {
            delete this.list[name];
        }
    }
}
let bus = new Bus();
export default bus;</pre><p>7) <code>Vue.set</code> <code>this.$set</code> 废弃</p>
<p>8.) vuex 修改</p><pre class="crayon-plain-tag">import { createStore } from 'vuex';
export default createStore({...})</pre><p>9) vue-router 修改</p><pre class="crayon-plain-tag">// vue2
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
const router =  new Router({
  routes: [...]
})

// 修改为：

// vue3
import { createRouter,createWebHashHistory } from 'vue-router';
const router =  new createRouter({
  history: createWebHashHistory(),       // 可有其它选项
  routes: [...]
})</pre><p>据说完成以上几个方面的修改，大多数 vue2 项目即可完成技术栈到 vue3 的迁移。</p>
<p>参考链接：</p>
<p>&#8211; https://www.cnblogs.com/thinkingthigh/p/15529082.html</p>
<p>最后附上一个语法书写上的解释，对老夫这样的小白有用：</p><pre class="crayon-plain-tag">// 直接绑定法
Vue.prototype.$EventBus = new Vue()

// 等于这种写法
const eve = new Vue()
Object.defineProperty(Vue.prototype,'$bus',{
  get() {
    return eve
  }
})

// 等于这种写法
const eve = new Vue()
Object.defineProperties(Vue.prototype, {
    $bus: {
        get() {
            return eve
        }
    }
})</pre><p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2022/06/27/%e8%a2%ab%e5%8a%a8%e4%ba%86%e8%a7%a3%e7%9a%84-javascript-%e5%87%8c%e4%b9%b1%e7%9f%a5%e8%af%86/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Flutter 开发要依赖 Chrome？</title>
		<link>https://www.somedoc.net/2021/10/08/flutter-%e5%bc%80%e5%8f%91%e8%a6%81%e4%be%9d%e8%b5%96-chrome%ef%bc%9f/</link>
					<comments>https://www.somedoc.net/2021/10/08/flutter-%e5%bc%80%e5%8f%91%e8%a6%81%e4%be%9d%e8%b5%96-chrome%ef%bc%9f/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Fri, 08 Oct 2021 04:01:00 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[问题解决]]></category>
		<category><![CDATA[Flutter]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=4908</guid>

					<description><![CDATA[刚才在命令行下更新 flutter 到 2.5.2，flut <a href="https://www.somedoc.net/2021/10/08/flutter-%e5%bc%80%e5%8f%91%e8%a6%81%e4%be%9d%e8%b5%96-chrome%ef%bc%9f/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>刚才在命令行下更新 flutter 到 2.5.2，<code>flutter doctor -v</code> 的输出里有一个警告，说没有找到 Chrome。这是因为老夫历来以 Firefox 为主力浏览器，Chrome 能少用就少用，自从新版的 Microsoft Edge 发布以来，更是直接就把 Chrome 删除了。</p>
<p>看提示，似乎 Flutter 也并不要求必须是 Chrome，因为可以定义一个名为 <code>CHROME_EXECUTABLE</code> 的环境变量来指定浏览器，想必可能是为 Chromium 的用户的留的口子，但既然 Edge 现在也是相同的内核，恐怕也不是不能用。Edge 的可执行文件全路径是 <code>C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe</code>，在指定时生怕空格作祟，特意在首尾添加了引号，结果是 Flutter 不认，去掉引号，也无暇测试是否允许路径中存在空格了，直接指定为 8.3 短路径格式的 <code>C:\Progra~2\Microsoft\Edge\Application\msedge.exe</code> 后就认可了。不过这只是通过了 flutter doctor 的检测，真实工作起来是不是有别的坑还有待以后验证查看。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2021/10/08/flutter-%e5%bc%80%e5%8f%91%e8%a6%81%e4%be%9d%e8%b5%96-chrome%ef%bc%9f/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
