<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	
	>
<channel>
	<title>
	〈ML5.js 神經網路 開發圖像辨識〉的留言	</title>
	<atom:link href="https://www.letswrite.tw/ml5-image-classifier/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.letswrite.tw/ml5-image-classifier/</link>
	<description>前端工程師 August 的學習筆記 -- solving problems, in simple ways.</description>
	<lastBuildDate>Fri, 19 Dec 2025 11:58:59 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>
		留言者: Nathan Cheng 鄭柏昇		</title>
		<link>https://www.letswrite.tw/ml5-image-classifier/#comment-235</link>

		<dc:creator><![CDATA[Nathan Cheng 鄭柏昇]]></dc:creator>
		<pubDate>Sun, 30 May 2021 07:39:38 +0000</pubDate>
		<guid isPermaLink="false">http://localhost:3001/?p=580#comment-235</guid>

					<description><![CDATA[給正在尋找使用Vue proj + cdn引入的朋友們參考：

由於p5.js、ml5.js 在npm的支援度不高，若是使用Vue專案建置的人，
引入p5.js、ml5.js cdn的方式可以如下:

1.在專案中建立新資料夾(與src/assets同級)，我取名為js-loader，並在其中建立index.js
2.在index.js中使用inject手法，引入外部cdn並提供回傳函數，以及確保不會多次載入

&lt;pre class=&quot;ql-syntax&quot; spellcheck=&quot;false&quot;&gt;// Load p5.js
    export function loadP5(callback){
        const existingScript = document.getElementById(&#039;p5js&#039;);

        if (!existingScript) {
            const script = document.createElement(&#039;script&#039;);
            script.src = &#039;https://cdn.jsdelivr.net/npm/p5@1.3.1/lib/p5.min.js&#039;;
            script.id = &#039;p5js&#039;;
            document.body.appendChild(script);
    
            script.onload = () =&#062; {
                if (callback) callback();
            };
        }
        if (existingScript &#038;&#038; callback) callback();
    };
    //Load ml5.js
    export function loadML5(callback){
        const existingScript = document.getElementById(&#039;ml5js&#039;);
    
        if (!existingScript) {
            const script = document.createElement(&#039;script&#039;);
            script.src = &#039;https://unpkg.com/ml5@latest/dist/ml5.min.js&#039;;
            script.id = &#039;ml5js&#039;;
            document.body.appendChild(script);
    
            script.onload = () =&#062; {
                if (callback) callback();
            };
        }
        if (existingScript &#038;&#038; callback) callback();
    };
&lt;/pre&gt;

3.在.vue頁面的script區塊引入:

&lt;pre class=&quot;ql-syntax&quot; spellcheck=&quot;false&quot;&gt;import * as jsLoader from &quot;@/js-loader&quot;;
&lt;/pre&gt;

4.在mount的部分 (確保cdn都引入的情況)

&lt;pre class=&quot;ql-syntax&quot; spellcheck=&quot;false&quot;&gt;&#160;&#160;&#160;&#160;mounted(){
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;jsLoader.loadML5(()=&#062;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;console.log(&#039;已載入ml5.js&#039;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;});
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;jsLoader.loadP5(()=&#062;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;console.log(&#039;已載入p5.js&#039;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;});
&#160;&#160;&#160;&#160;},
&lt;/pre&gt;

5.完成，可以使用ml5.js + p5.js在你的vue專案了

#資料參考:
自己踩雷、&lt;a href=&quot;https://cleverbeagle.com/blog/articles/tutorial-how-to-load-third-party-scripts-dynamically-in-javascript&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow ugc&quot;&gt;這裡&lt;/a&gt;]]></description>
			<content:encoded><![CDATA[<p>給正在尋找使用Vue proj + cdn引入的朋友們參考：</p>
<p>由於p5.js、ml5.js 在npm的支援度不高，若是使用Vue專案建置的人，<br />
引入p5.js、ml5.js cdn的方式可以如下:</p>
<p>1.在專案中建立新資料夾(與src/assets同級)，我取名為js-loader，並在其中建立index.js<br />
2.在index.js中使用inject手法，引入外部cdn並提供回傳函數，以及確保不會多次載入</p>
<pre class="ql-syntax" spellcheck="false">// Load p5.js
    export function loadP5(callback){
        const existingScript = document.getElementById('p5js');

        if (!existingScript) {
            const script = document.createElement('script');
            script.src = 'https://cdn.jsdelivr.net/npm/p5@1.3.1/lib/p5.min.js';
            script.id = 'p5js';
            document.body.appendChild(script);
    
            script.onload = () =&gt; {
                if (callback) callback();
            };
        }
        if (existingScript &amp;&amp; callback) callback();
    };
    //Load ml5.js
    export function loadML5(callback){
        const existingScript = document.getElementById('ml5js');
    
        if (!existingScript) {
            const script = document.createElement('script');
            script.src = 'https://unpkg.com/ml5@latest/dist/ml5.min.js';
            script.id = 'ml5js';
            document.body.appendChild(script);
    
            script.onload = () =&gt; {
                if (callback) callback();
            };
        }
        if (existingScript &amp;&amp; callback) callback();
    };
</pre>
<p>3.在.vue頁面的script區塊引入:</p>
<pre class="ql-syntax" spellcheck="false">import * as jsLoader from "@/js-loader";
</pre>
<p>4.在mount的部分 (確保cdn都引入的情況)</p>
<pre class="ql-syntax" spellcheck="false">&nbsp;&nbsp;&nbsp;&nbsp;mounted(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jsLoader.loadML5(()=&gt;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('已載入ml5.js');
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jsLoader.loadP5(()=&gt;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('已載入p5.js');
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;},
</pre>
<p>5.完成，可以使用ml5.js + p5.js在你的vue專案了</p>
<p>#資料參考:<br />
自己踩雷、<a href="https://cleverbeagle.com/blog/articles/tutorial-how-to-load-third-party-scripts-dynamically-in-javascript" target="_blank" rel="noopener nofollow ugc">這裡</a></p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
