<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Select * on Medium]]></title>
        <description><![CDATA[Stories by Select * on Medium]]></description>
        <link>https://medium.com/@selectasterisk?source=rss-7bd36933997e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uVknW-Gciec65CnwYCsFKA.png</url>
            <title>Stories by Select * on Medium</title>
            <link>https://medium.com/@selectasterisk?source=rss-7bd36933997e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:03:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@selectasterisk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[ Vue.js ] 元件: Components]]></title>
            <link>https://medium.com/selectprogram/vue-js-%E5%85%83%E4%BB%B6-components-49494d53f316?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/49494d53f316</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sun, 15 Aug 2021 01:38:05 GMT</pubDate>
            <atom:updated>2021-08-15T01:38:05.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*4U8D_YhHt8mRYQLnJEzaeg.png" /></figure><p>Vue能夠將部分程式碼封裝起來元件化，即為Components(元件)。<br>就像是把原本整頁的HTML拆分成各個小元件，再由這些元件組合重想要的HTML畫面。元件能夠重複呼叫、使用，達到元件共用的效果。</p><p>像傳統網頁結構可能會由header、nav、main、footer...等標籤所組成。<br>Vue則可將這四塊去塊拆成四個Components，四個分別有各自的template、script、style的vue檔案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jIpo7dxOQw0kegO4XDI6OQ.png" /></figure><blockquote><strong><em>選擇重複共用程式碼</em></strong></blockquote><p>在之前所使用的<a href="https://medium.com/selectprogram/vue-js-vue%E6%8C%87%E4%BB%A4-v-bind-fca1937d205c"><strong>專案</strong></a>中，可以看到src/views資料夾底下BindDemo.vue與DataDemo.vue的template中，都會有一段相同的程式碼重複。<br> &lt;h1&gt;Demo : {{ $route.params.title }}&lt;/h1&gt;<br>這段程式碼是為了在內容最上層顯示單元的title，接下來就把這一段title元件化成Components吧。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RejZi3wBZe66-B3AneHaw.png" /><figcaption>src/views資料夾底下的BindDemo.vue與DataDemo.vue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b2YaFCVdB8XOWkIPdVkexA.png" /></figure><blockquote><strong><em>建立Components</em></strong></blockquote><pre>建立vue檔案，作為共用的元件。</pre><p>在src/components資料夾底下建立vue檔案，命名為Title.vue。<br>並新增&lt;template&gt;區塊，加入&lt;h1&gt;Demo : {{ $route.params.title }}&lt;/h1&gt;這段程式碼，讓這個Title.vue能夠依照route的title參數來顯示title(關於route的設定可參考<a href="https://medium.com/selectprogram/vue-js-%E8%B7%AF%E7%94%B1-vue-router-63b9edb0a5f1"><strong>這裡</strong></a>)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*r9234g3zQ1P5C40g4366Ew.png" /><figcaption>src/components/Title.vue</figcaption></figure><blockquote><strong><em>註冊Components並使用</em></strong></blockquote><pre>在要使用components的地方，將vue檔案引入(import)，設定為components並輸出(export)使用。</pre><p>在src/views/BindDemo.vue的&lt;script&gt;區塊中import在src/components資料夾底下的Title.vue，並命名為ComponentTitle。</p><pre><strong>import ComponentTitle from &quot;../components/Title.vue&quot;;</strong></pre><p>並在export default {...}中定義components為引入的ComponentTitle。</p><pre><strong>components: {<br>  ComponentTitle,<br>}</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*1i-unvsrrLRz02MnmH9uCw.png" /><figcaption>src/views/BindDemo.vue的&lt;script&gt;</figcaption></figure><p>在src/views/BindDemo.vue的&lt;template&gt;區塊中，刪除原先用來顯示title的程式碼&lt;h1&gt;Demo : {{ $route.params.title }}&lt;/h1&gt;，加入以下程式碼:</p><pre><strong>&lt;ComponentTitle&gt;&lt;/ComponentTitle&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*GTH8UMgHnpeT2HOhb2tb0g.png" /><figcaption>src/views/BindDemo.vue的&lt;template&gt;</figcaption></figure><p>存檔執行後，點選v-bind選項，可以看到title的顯示。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4UuPfBWUVdqpX_ZQuV3Gg.png" /></figure><blockquote><strong><em>局部註冊與全域註冊</em></strong></blockquote><pre>components有局部註冊與全域註冊，差別在於局部註冊就要在每次使用時引入要使用的vue檔案並設定components，全域註冊則是在vue實體建立時註冊，接下來在整個專案都可直接使用。</pre><p>前面在src/views/BindDemo.vue當中設定的components即為局部註冊，如果要讓另一個頁面也套用Title.vue作為components，就需要在另一個頁面做一次註冊動作。(如src/views/DataDemo.vue)</p><p>如果不想要每一次使用都需要先註冊元件的話，可以使用全域註冊的方式。</p><p>在src/main.js中import在src/components資料夾底下的Title.vue，並命名為ComponentTitle。</p><pre><strong>import ComponentTitle from &quot;./components/Title.vue&quot;;</strong></pre><p>並在createApp後，註冊components。</p><pre><strong>app.component(&quot;ComponentTitle&quot;, ComponentTitle);</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*VNKEFjwLMNMUAgFapPtEVg.png" /><figcaption>src/main.js</figcaption></figure><p>接下來，直接在src/views/DataDemo.vue的&lt;template&gt;的區塊中加入</p><pre><strong>&lt;ComponentTitle&gt;&lt;/ComponentTitle&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*uuPHQ7eAZqQQv9H3lBf7ag.png" /><figcaption>src/views/DataDemo.vue的&lt;template&gt;</figcaption></figure><p>存檔執行後，點選data選項，可以看到畫面能夠直接呈現components的內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWHWTKw9qOJfN4juZAkoHA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49494d53f316" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/vue-js-%E5%85%83%E4%BB%B6-components-49494d53f316">[ Vue.js ] 元件: Components</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[ Vue.js ] Vue指令: v-bind]]></title>
            <link>https://medium.com/selectprogram/vue-js-vue%E6%8C%87%E4%BB%A4-v-bind-fca1937d205c?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fca1937d205c</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[v-bind]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sun, 08 Aug 2021 15:01:16 GMT</pubDate>
            <atom:updated>2021-08-08T15:03:11.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*YnEZv5T2I7V0m3KwoUb1vg.png" /></figure><p>Vue directive(指令)，是指v-開頭的Vue語法。<br>Vue的v-bind可以用來綁定HTML屬性、CSS樣式與Style。</p><p><a href="https://medium.com/selectprogram/vue-js-%E8%B3%87%E6%96%99%E7%B6%81%E5%AE%9A-data-71a359548952"><strong>沿用專案</strong></a>並加入新的router-view:</p><p>src/view加入檔案，命名為BindDemo.vue，並在檔案中加入template。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*WOtsW8yIf8fN9B5nWy4uLg.png" /><figcaption>src/view/BindDemo.vue的template</figcaption></figure><p>src/router/index.js中，import BindDemo.vue並設定routes。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*h2k1UTBEn-wjOPO77LrLpQ.png" /><figcaption>src/router/index.js</figcaption></figure><p>src/Layout.vue的&lt;template&gt;中加入&lt;router-link&gt; 設定BindDemo路徑與參數。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*x2SUvIAVFKxH-a6rCPEReQ.png" /><figcaption>src/Layout.vue的template</figcaption></figure><p>存檔後執行，點選頁面右側v-bind選單，顯示畫面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pg0gNVLlR80GdVEWv355ZA.png" /></figure><p>接下來開始實作v-bind。</p><blockquote><strong><em>v-bind 屬性綁定</em></strong></blockquote><pre>v-bind可以用來綁定HTML上的屬性(attribute)，對HTML屬性作綁定與操作，如title、style、class、disable…等，如同以往以DOM(Document Object Model)對HTML上的屬性作操作一樣。</pre><p>在Vue中，綁定HTML屬性的語法為 v-bind:屬性名稱 = &quot;屬性的值&quot;。<br>可以透過v-bind綁定各種屬性，如以下:</p><h4>title屬性</h4><p>在src/views/BindDemo.vue的template加入&lt;input&gt;標籤並設定HTML屬性title為&quot;TitleValue&quot;。</p><p>v-bind:title=&quot;TitleValue&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*HDAfJy-9aXvbWAs9Hjx_qg.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>在src/views/BindDemo.vue加入script並設定data與title的值，export出來讓v-bind做綁定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*dNsrNMpayZ4Q9GPeSGoyOA.png" /><figcaption>src/views/BindDemo.vue加入script</figcaption></figure><p>存檔執行後，將滑鼠游標放置在text上，即可跑出title &quot;請輸入內容&quot;。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uWtcRE5o3fyeimnyTrGkbg.png" /></figure><h4>disabled屬性</h4><p>在剛剛建立的&lt;input&gt;標籤設定HTML屬性disabled為&quot;true&quot;。</p><p>v-bind:disabled=&quot;true&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*qtXzKeOddTVM9tFA7_KoLg.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>存檔執行，即可看到text反灰無法輸入。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bItKY2q52HLZTHfEYB9HHw.png" /></figure><h4>src屬性</h4><p>在template中加入&lt;img/&gt;並指定src為&quot;SrcURL&quot;。</p><p>v-bind:src=&quot;SrcURL&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*xsyPEbjEKlglUEPIz3I8bQ.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>在script中新增SrcURL的值，export出來讓v-bind做綁定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*Mg7hR1WZ2Ryvz_BcFMaC4w.png" /><figcaption>src/views/BindDemo.vue的scrtip</figcaption></figure><p>存檔執行後，即可看到image。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnYLXqVBPPnTuXott6UfQQ.png" /></figure><h4>v-bind縮寫</h4><p>v-bind語法也可以縮寫，從原本的v-bind:屬性名稱改為:屬性名稱。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*Am2dHwQyjtjn84iWrWLWoQ.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>除了上面的HTML屬性外，v-bind也能夠綁定其他各種的HTML屬性，可參考 <a href="https://www.w3schools.com/tags/ref_attributes.asp">https://www.w3schools.com/tags/ref_attributes.asp</a>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*Wd-A6G43qE2IflMhVy-CVA.png" /></figure><blockquote><strong><em>v-bind Class綁定</em></strong></blockquote><pre>v-bind綁定Class屬性。透過設定Class的綁定與否，可以達到動態切換Class的效果。</pre><p>在src/views/BindDemo.vue加入&lt;style&gt;區塊與MyCSS。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*Fphsm5u5z8H8V0WGbPt7sA.png" /><figcaption>src/views/BindDemo.vue的style</figcaption></figure><p>在&lt;script&gt;區塊的data中增加MyCSS。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01VHGzLOky-Giu9bOFc_GA.png" /><figcaption>src/views/BindDemo.vue的style</figcaption></figure><p>在&lt;template&gt;下方增加&lt;label&gt;綁定class=&quot;MyCSS&quot;。</p><p>:class=&quot;MyCSS&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*DuwYpmN9o9jk2REcV-6vHw.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>存檔執行，即可看到My CSS Sytle與榜定的calss。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvUgQYR1iKfVZXlw0KMOzg.png" /></figure><p>另外，可以在data定義變數來判斷是否套用class，用來動態綁定class。</p><p>在&lt;script&gt;區塊中加入兩個屬性，isActive與notActiv，值分別為true與false。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*Q4_ufMsNQX7vxL-r-YSu1Q.png" /><figcaption>src/views/BindDemo.vue的script</figcaption></figure><p>將原本的&lt;label&gt;增加為兩個，分別以:class=&quot;{class名稱: 綁定與否}&quot;，各自設定為:class=&quot;{ MyCSS: isActive }&quot;與:class=&quot;{ MyCSS: notActive }&quot;。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*y5FtSkoPEyetmg2jOt_rZw.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>存檔執行後，可以看到<strong>#17</strong>因為是isActive: true，所以會綁定class。<br>而<strong>Shohei Ohtani</strong>則是notActive: fals所以不會有class效果。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8eisHSoKBA94Bqf_zCJPA.png" /></figure><h4>綁定多個class</h4><p>class的綁定，也可以用陣列的方式[{class1名稱},{class2名稱}]來綁定多個class。</p><p>在&lt;style&gt;區塊增加MyCSS2，其背景顏色與文字顏色跟MyCSS相反。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*2TqiRZ6gdJJHge-Pl5NT6Q.png" /><figcaption>src/views/BindDemo.vue的style</figcaption></figure><p>在&lt;style&gt;區塊的data中增加MyCSS2。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*uljyWqizXwQN6bXAetllQg.png" /><figcaption>src/views/BindDemo.vue的script</figcaption></figure><p>在&lt;template&gt;區塊中，將兩個&lt;label&gt;分別以下面語法做綁定</p><p>:class=&quot;[{ MyCSS: isActive }, { MyCSS2: notActive }]&quot;<br>:class=&quot;[{ MyCSS: notActive }, { MyCSS2: isActive }]&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*pCPHpa7NWGPMDvjQt5-z0g.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>存檔執行後，可以看到:<br><strong>#17</strong>的綁定只有MyCSS為isActive: true，所以只會呈現MyCSS的效果(紅底白字)。<br>而<strong>Shohei Ohtani</strong>則是MyCSS2為isActive: true，所以只會有MyCSS2的效果(白底紅字)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFSE8Ad2ZCFLR45fVnvW-A.png" /></figure><h4>套用bootstrap</h4><p>安裝bootstrap，並綁定bootstrap的CSS。</p><h4>npm安裝bootstrap</h4><p>開啟終端機，輸入:<br><strong>npm install bootstrap</strong></p><p>安裝完後，就可以看到node_modules多了bootstrap資料夾。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*g3tcj5TXQhcQa8tRdPTtNw.png" /></figure><p>在src/main.js中import bootstrap.min.css，並在建立Vue實體時use()。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*eHxsXZt5O-B40iO0aDpubw.png" /><figcaption>src/main.js</figcaption></figure><p>在src/views/BindDemo.vue的&lt;template&gt;區塊中變更第6行&lt;input&gt;的HTML屬性，指定 :class=&quot;[&#39;form-control&#39;]&quot;。(會用[&#39; &#39;]包住class，是因為class名稱有<strong>&quot;-&quot;</strong>，需要特別做處理)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*RCi3t1f0I4cWOYBgUOsTCg.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>存檔執行，可以看到input套用了bootstrap的class。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zWOHAyFejCuvS8jbp5Zryw.png" /></figure><blockquote><strong><em>v-bind Style綁定</em></strong></blockquote><pre>透過 :style 語法，綁定一個或多個inline-style樣式。</pre><p>如果原本想寫在&lt;div&gt;標籤內的style如下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*Y2fWFxF97zKdlTw6Tk6Rtw.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>在vue則可寫成 :style=&quot;要綁定的CSS樣式&quot;。</p><p>在&lt;div&gt;綁定style樣式為&quot;divCSS&quot;。</p><p>:style=&quot;divCSS&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*Zc8BNXDANLT9TQwMHEWeSg.png" /><figcaption>src/views/BindDemo.vue的template</figcaption></figure><p>另外再&lt;script&gt;區塊加入&quot;divCSS&quot;。<br>其中border-style跟border-color，因為有&quot;-&quot;的關係，要改成駝峰式的寫法。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*E2tBPQg-iXePzHft9GBDQw.png" /><figcaption>src/views/BindDemo.vue的script</figcaption></figure><p>存檔執行，顯示的畫面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WXx9Df1rOimnbpj7PFXCg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fca1937d205c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/vue-js-vue%E6%8C%87%E4%BB%A4-v-bind-fca1937d205c">[ Vue.js ] Vue指令: v-bind</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[ Vue.js ] 資料綁定: Data]]></title>
            <link>https://medium.com/selectprogram/vue-js-%E8%B3%87%E6%96%99%E7%B6%81%E5%AE%9A-data-71a359548952?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/71a359548952</guid>
            <category><![CDATA[axios]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Mon, 26 Jul 2021 15:39:48 GMT</pubDate>
            <atom:updated>2021-07-27T02:56:13.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*unqEdA8yOmgyF0QeIOMZuQ.png" /></figure><p>Vue的data屬性，可以用來存放資料，供後續的畫面呈現與操作。<br>data中的資料可以搭配v-model達到資料雙向綁定，當data資料變更時，呈現在畫面上的資料也會隨著變更。<br>以及import外部JSON檔案至data中和使用Axios發起Http Request將回傳值放至data中。</p><blockquote><strong><em>專案準備</em></strong></blockquote><pre>為了demo方便，這邊調整先前建立的<a href="https://medium.com/selectprogram/vue-js-%E8%B7%AF%E7%94%B1-vue-router-63b9edb0a5f1"><strong>專案</strong></a>，將左側選單加入本次data的選項，並將demo程式碼顯示在右側router-view中。</pre><h4>新增views</h4><p>src/views資料夾，新增DataDemo.vue。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EcKs-0wDqMgtclyZ8OIfrA.png" /><figcaption>src/views/DataDemo.vue的template</figcaption></figure><h4>調整router</h4><p>src/router/index.js，將routers調整，加入DataDemo.vue的路徑。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NFa-e3dBQwJIcCEFH7vKA.png" /><figcaption>src/router/index.js</figcaption></figure><h4>調整Layout</h4><p>src/Layout.vue，變更router-link連結，指向DataDemo。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*GIGQdqhRdj_XmuYghjeoDg.png" /><figcaption>src/Layout.vue的template</figcaption></figure><p>存檔後執行，點選左側選單的data，可以看到DataDemo的畫面，接下來將在DataDemo.vue裡面寫進data的demo程式並呈現在畫面上。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hrpuQ1YH69ssYKWDfBTiNg.png" /></figure><blockquote><strong><em>data語法</em></strong></blockquote><pre>data屬性寫在vue檔案中script區塊內的export default { }中，讓設定完的資料匯出做使用。</pre><p>開啟src/views/DataDemo.vue，加入&lt;script/&gt;區塊以及export default {};，並在export default中加入data function。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*d5AkNPwAz0jXzK_hRb9l1g.png" /><figcaption>src/views/DataDemo.vue</figcaption></figure><pre>data() {<br>     return {<br>         message: &quot;Hello Vue&quot;,<br>     };<br>},</pre><p>export default中的程式碼，建立了一個data物件，data物件會return一個名稱為message，值為&quot;Hello Vue&quot;的屬性。</p><p>接著將message綁定在template中，讓畫面呈現message的值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*9SBNVtxZg3x26JcWlykZrw.png" /><figcaption>src/views/DataDemo.vue</figcaption></figure><p>&lt;h2&gt;message的值為 : {{ message }}&lt;/h2&gt;中以{{ }}來綁定data中message的值。</p><p>存檔執行後，即可看到&quot;Hello Vue&quot;。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owpmwIOwxJOlJY91YTKbZQ.png" /></figure><blockquote><strong><em>v-model 雙向綁定</em></strong></blockquote><pre>利用v-model將data中的資料與畫面做雙向綁定。<br>當資料中的值變更時，呈現的值也會跟著做變動。</pre><p>src/views/DataDemo.vue的template中加入:<br>&lt;input type=&quot;text&quot; v-model=&quot;message&quot; /&gt;。</p><p>v-model=&quot;message&quot; 將message屬性與input中的值做結合，所以當input把message的值做變更時，整個畫面所渲染的message值也會跟著變動。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*EAPbyfTC_8GIH-C0JKBhQg.png" /><figcaption>src/views/DataDemo.vue</figcaption></figure><p>執行後，input標籤會先綁定message的值&quot;Hello Vue&quot;，接著當input變動，可以看到上方的值也會跟著改變。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpleoFzdMneU86TC9z6uDg.png" /></figure><blockquote><strong><em>data: List[ ]</em></strong></blockquote><pre>data中的值也可以用list陣列來顯示。</pre><p>src/views/DataDemo.vue的data()中，加入checked屬性，值為空陣列[ ]。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*6CWP9XeA-XMTQkwbYwD_oA.png" /><figcaption>src/views/DataDemo.vue</figcaption></figure><p>src/views/DataDemo.vue的template中，加入五個checkbox，value為&quot;選項一&quot;~&quot;選項五&quot;，並以v-model綁定checked屬性的值。<br>並在下方增加&lt;h3&gt;選擇了 : {{ checked }}&lt;/h3&gt;用來顯示被選取的checked值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*Lzfow299CFKv2AvKokh3kA.png" /><figcaption>src/views/DataDemo.vue</figcaption></figure><p>執行後，勾選選項，可以看到checked陣列增加了被勾選的值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klrlzGLNHZa6KQfMxipRWQ.png" /></figure><blockquote><strong><em>引入其他檔案的資料</em></strong></blockquote><pre>將其他檔案中的資料引入至data中使用。</pre><p>新增src/data資料夾，並在底下新增ScoreData.js檔案，並在裡面加入學生姓名與科目成績的JSON資料。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQ8HiYXguMFYLER3IYHziw.png" /><figcaption>src/data/ScoreData.js</figcaption></figure><p>src/views/DataDemo.vue的&lt;script/&gt;中引入(import)ScoreData.js檔案</p><pre>import ScoreData from &quot;../data/ScoreData&quot;;</pre><p>並設一個名為scoredata的屬型接收ScoreData的值。</p><pre>scoredata: ScoreData</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*kWL6HnqaxtoE0xXinA4wDQ.png" /><figcaption>src/views/DataDemo.vue的srcipt</figcaption></figure><p>src/views/DataDemo.vue的template中加入&lt;table&gt;，並將scoredata的資料放進&lt;table&gt;中，讓ScoreData檔案中的JSON資料能依序顯示在Table之中。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPdSebCRvcTRagW7sYNW5w.png" /><figcaption>src/views/DataDemo.vue的template</figcaption></figure><p>然後src/views/DataDemo.vue下方加入&lt;style/&gt;與CSS美化一下Table。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*s7eNy83wrF3O-W731p8OiQ.png" /><figcaption>src/views/DataDemo.vue的style</figcaption></figure><p>執行後，可以看到table與ScoreData的資料。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DpGuURE_6C8216kP6Se2YQ.png" /></figure><blockquote><strong><em>Axios get外部資料</em></strong></blockquote><pre>透過Axios發出Http Request，接受外部資料並放置data中。</pre><p>Axios是一個套件，讓前端瀏覽器可以發起POST、GET、PUT...等 Http Request。<br>(詳細可參考<a href="https://axios-http.com/docs/intro">https://axios-http.com/docs/intro</a>。)</p><h4><strong><em>安裝Axios</em></strong></h4><p>使用npm安裝axios，開啟終端機輸入:<br><strong>npm install axios</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNN_xzAhAJBw02Zmnnn2nw.png" /><figcaption>終端機畫面</figcaption></figure><h4>axios配置</h4><p>新增src/api資料夾與Api.js檔案。<br>Api.js這個檔案是用來統一管理API用的，把Axios的Request寫在這邊並export輸出，要使用時import這個Api.js檔案使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR97L5IgcM39y6A9bFo1Fg.png" /><figcaption>src/api/Api.js</figcaption></figure><p>這邊要呼叫的URL為:<br><a href="http://lookup-service-prod.mlb.com/json/named.sport_pitching_tm.bam?league_list_id=&#39;mlb&#39;&amp;game_type=&#39;R&#39;&amp;season=&#39;2021&#39;&amp;player_id=&#39;660271&#39;">http://lookup-service-prod.mlb.com/json/named.sport_pitching_tm.bam?league_list_id=&#39;mlb&#39;&amp;game_type=&#39;R&#39;&amp;season=&#39;2021&#39;&amp;player_id=&#39;660271&#39;</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UfTnPNXWI2K6anuyfXayaQ.png" /><figcaption>http://lookup-service-prod.mlb.com/json/named.sport_pitching_tm.bam?league_list_id=&#39;mlb&#39;&amp;game_type=&#39;R&#39;&amp;season=&#39;2021&#39;&amp;player_id=&#39;660271&#39;回傳資料</figcaption></figure><p>這是<a href="https://appac.github.io/mlb-data-api-docs/"><strong>MLB Data API</strong></a>，上面的URL是查詢選手成績的API，查詢的選手為編號(player_id)660271的Shohei Ohtani。</p><p>接下來，將這個URL的Axios Request寫在src/api/Api.js裡。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4q92khc6Z1SkHTbS1ODFcw.png" /><figcaption>src/api/Api.js</figcaption></figure><p>首先，import axios，並定義為名稱axios。</p><p>接著宣告PitchingStatsRequest為axios.create，建立axios實體並定義baseURL為http://lookup-service-prod.mlb.com/json。</p><p>最後，export匯出名稱為getPitchingStats的方法，方法內為PitchingStatsRequest的get Http Request以及定義url(https://medium.com/&quot;/named.sport_pitching_tm.bam&quot;)和參數(params)。</p><h4>引入並使用</h4><p>在src/views/DataDemo.vue的&lt;script/&gt;區塊中引入Api.js。</p><pre>import { getPitchingStats } from &quot;../api/Api&quot;;</pre><p>並在data()中加入名為pitchingdata的屬性，值得來源為getPitchingStats<br>所取回的資料，這邊在使用getPitchingStats時，會設定參數(params)並將回傳(resopnse)的值擷取到要的資料，並將值給至pitchingdata。</p><pre>pitchingdata: getPitchingStats({<br>  params: {<br>    league_list_id: &quot;&#39;mlb&#39;&quot;,<br>    game_type: &quot;&#39;R&#39;&quot;,<br>    season: &quot;&#39;2021&#39;&quot;,<br>    player_id: &quot;&#39;660271&#39;&quot;,<br>  },<br>})<br>.then((response) =&gt; {<br> this.pitchingdata=response.data.sport_pitching_tm.queryResults.row;<br>})<br>.catch((err) =&gt; {<br>console.log(err);<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*n2yuw_YmfvcRyKb03EKVPQ.png" /><figcaption>src/views/DataDemo.vue的script</figcaption></figure><p>接下來，在src/views/DataDemo.vue的template加入以下</p><p>&lt;img&gt; 抓了一個URL，顯示Ohtani的照片。</p><p>&lt;h3&gt; 顯示名稱 Shohei Ohtani。</p><p>&lt;table&gt; 顯示pitchingdata的成績資料。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2K2h3FSioqWNvalSqDNILw.png" /><figcaption>src/views/DataDemo.vue的template</figcaption></figure><p>執行可以看到照片、名字、成績。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnFQyBEDePe-JsAu4Gb0hA.png" /></figure><blockquote><strong><em>程式碼</em></strong></blockquote><pre>紀錄一下從頭到尾的完整程式碼。</pre><h4>src/views/DataDemo.vue</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aabaa41472593caaafb933394ce216e8/href">https://medium.com/media/aabaa41472593caaafb933394ce216e8/href</a></iframe><h4>src/Layout.vue</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/454aba709a84f3008f380fd57b388666/href">https://medium.com/media/454aba709a84f3008f380fd57b388666/href</a></iframe><h4>src/router/index.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36ecba034d054d19767852b0685b2388/href">https://medium.com/media/36ecba034d054d19767852b0685b2388/href</a></iframe><h4>src/data/ScoreData.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6addfebe1bbf56177fa6410824d2ac0/href">https://medium.com/media/a6addfebe1bbf56177fa6410824d2ac0/href</a></iframe><h4>src/api/Api.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fab3f3037f11ccef1301753d31fd084/href">https://medium.com/media/9fab3f3037f11ccef1301753d31fd084/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71a359548952" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/vue-js-%E8%B3%87%E6%96%99%E7%B6%81%E5%AE%9A-data-71a359548952">[ Vue.js ] 資料綁定: Data</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[ Vue.js ] 路由 : Vue Router]]></title>
            <link>https://medium.com/selectprogram/vue-js-%E8%B7%AF%E7%94%B1-vue-router-63b9edb0a5f1?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/63b9edb0a5f1</guid>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sun, 18 Jul 2021 08:26:15 GMT</pubDate>
            <atom:updated>2021-07-24T14:09:49.898Z</atom:updated>
            <content:encoded><![CDATA[<h3>[ Vue.js ] 路由 : Vue Router</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*fZD8nbk2FFHumbVYGaKvNQ.png" /></figure><p>Vue Router為Vue官方提供的路由管理器，讓前端頁面可以操作route。<br>本篇將利用router-link與router-view讓頁面可以透過左側選單(side navigation bar)來切換右側子頁面內容，並以$route.params傳遞參數。</p><h4>步驟</h4><ul><li>安裝Vue Router</li><li>建立Layout頁面</li><li>建立view頁面</li><li>設定route</li></ul><p>最後的成品如下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*icepjcMxRVwTWIRJiYdkVw.png" /></figure><blockquote><strong><em>安裝Vue Router</em></strong></blockquote><pre>使用Vue CLI安裝Vue Router。</pre><p>開啟終端機，輸入:<br><strong> </strong><strong>vue add router@next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*en4HJOuBHlNnygrJklhxHQ.png" /></figure><p>顯示是否使用 history mode 輸入Y，Enter繼續執行安裝。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yjaoB8CvTYsz2uZCLDbwNQ.png" /></figure><p>一直跑到出現 successfully，即安裝完畢。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ou88hCB49Kav1CZrf-4zyQ.png" /></figure><p>安裝完畢後，可以看到增加一些資料夾與檔案。</p><h4>router資料夾與index.js檔案</h4><p>index.js引入了vue-router，並建立routes來定義路由。<br>可以看到routes中定義了兩個路由。</p><pre><strong>{<br>  path: &quot;/&quot;,       </strong>//設定路徑為&quot;http://localhost/&quot;<strong><br>  name: &quot;Home&quot;,    </strong>//設定名稱為Home<strong><br>  component: Home, </strong>//設定component來源<strong><br>},<br>{<br>  path: &quot;/about&quot;,  </strong>//設定路徑為&quot;http://localhost/about&quot;<strong><br>  name: &quot;About&quot;,   </strong>//設定名稱為About<strong><br>  component: import(../views/About.vue), </strong>//設定component來源<strong><br>}</strong></pre><p>routers裡所設定的component即為子頁面(router-view)所想要顯示的內容，如果component設定為&quot;../views/About.vue&quot;，那麼內容就會顯示src/views/About.vue這個檔案的內容。</p><p>最後，宣告 router為createRouter()建立路由，並將router輸出(export)，讓其他頁面可以引入router作為元件使用。</p><pre>//createRouter為設定路由的method<br><strong>const router = createRouter({ </strong></pre><pre>  //將history設定為createWebHashHistory()<strong><br>  history: createWebHistory(process.env.BASE_URL),</strong></pre><pre>  //routes為routes: routes的縮寫<br><strong>  routes,<br>});</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nunPJqyKSMlU5EhypTrhXg.png" /><figcaption>src/router/index.js</figcaption></figure><h4>views資料夾與兩支vue檔案</h4><p>src/views資料夾底下的vue檔案為路由中component所對應的實體檔案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wSK_cKPpMZNUE_jFt4OYA.png" /><figcaption>src/views/Home.vue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38bjG4n2om7oMl3Gf4j1NA.png" /><figcaption>src/views/About.vue</figcaption></figure><h4>App.vue</h4><p>App.vue也跟原本不一樣了，多了&lt;router-link/&gt;與 &lt;router-view /&gt;標籤。</p><p><strong>&lt;router-link/&gt;</strong> <br>設定to屬性來指定路由。(router-link還有其他很多種屬性可以使用，可以參考<a href="https://router.vuejs.org/api/#router-link-props">這邊</a>)</p><p><strong>&lt;router-view/&gt; <br></strong>用來顯示路由所對應到的components(views資料夾底下的vue檔案)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F2_71BlG4EqsXmz95MkbKA.png" /><figcaption>src/App.vue</figcaption></figure><h4>main.js</h4><p>引入了router資料夾，並在createApp(App)時，多加了.use(router)。<br>語法是指，在建立Vue時，把前面src/router/index.js所定義的router加進Vue裡，這樣之後便可以使用設定好的路由讓Vue專案使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1f2Dg0E33S9Ji92C-GRhAw.png" /><figcaption>src/main.js</figcaption></figure><p>執行後可以看到，上方多了兩個連結，分別是Hoem與About，點選後可以切換Home與About畫面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vc800riwhW-O8ac7R4-neg.png" /></figure><p>接下來，來建立自己的首頁與選單menu，來切換顯示內容。</p><blockquote><strong><em>建立Layout</em></strong></blockquote><pre>建立一個Layout做為首頁，首頁包含了Header、左側選單、右側內容。</pre><p>在src/assets資料夾加入圖片，命名為icon.png，用來做header的icon圖片。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_xQTuuXjZ6kwgtsLIUeGTA.png" /></figure><p>在src底下新增Layout.vue檔案，並加入&lt;router-link/&gt;指定路由的路徑，以及&lt;router-view&gt;用來顯示路由所對應到的component。</p><p>程式碼如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca85fee0ef4130e0dc3f819cfe0e595d/href">https://medium.com/media/ca85fee0ef4130e0dc3f819cfe0e595d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSbbXcQ_FWCumlQhadKjUQ.png" /><figcaption>src/Layout.vue</figcaption></figure><p>接著，開啟src/main.js，調整App from 為&quot;./Layout.vue&quot;，讓首頁為Layout.vue。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXKpyrttMlw2XCGEN38Zuw.png" /><figcaption>src/main.js</figcaption></figure><p>這時候執行，會看到如下畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0KAMycftEsJfVZfIAT0weQ.png" /></figure><blockquote><strong><em>建立view</em></strong></blockquote><pre>建立三個view頁面，做為子頁面的顯示內容。</pre><p>在src/views資料夾底下新增子頁面，Nav1.vue、Nav2.vue、Nav3.vue。<br>給route的component使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAjq3ewzV4RAMll1GjpOQA.png" /><figcaption>src/views/Nav1.vue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXZSjLFk-tWhftOoyHPdLg.png" /><figcaption>src/views/Nav2.vue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zMQQigktDTfXcbDHsLML4w.png" /><figcaption>src/views/Nav3.vue</figcaption></figure><blockquote><strong><em>設定route</em></strong></blockquote><pre>設定路由與要對應的component。</pre><p>開啟src/router/index.js，分別引入views/Nav1.vue、views/Nav2.vue、views/Nav3.vue，並設定這三個畫面所對應的路徑。<br>最後，createRouter並輸出(export)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8FrFhQ86b2zeyNc3x8sJxg.png" /><figcaption>src/router/index.js</figcaption></figure><blockquote><strong><em>執行畫面</em></strong></blockquote><p>起始畫面如下。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fj2cTpJWONgUhDISFEOxSg.png" /></figure><p>點選連結1，顯示src/views/Nav1.vue的內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRT08CePNCdOL9-NCHSLjQ.png" /></figure><p>點選連結2，顯示src/views/Nav2.vue的內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wmLq3UgYkEclgBQqzbddaQ.png" /></figure><p>點選連結3，顯示src/views/Nav3.vue的內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYm39Wp2Go-OwPbUcV-ZHw.png" /></figure><blockquote><strong><em>後記</em></strong></blockquote><p>route除了傳遞路徑外，也可以設定路徑參數，讓母頁面可以傳遞參數給子頁面接受。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*nzI4KyQJ-1Xmc3O8hGpAnw.png" /><figcaption>來源:<a href="https://router.vuejs.org/guide/essentials/dynamic-matching.html">https://router.vuejs.org/guide/essentials/dynamic-matching.html</a></figcaption></figure><h4>pattern</h4><p>開啟src/route/index.js，將routes中的path參數做調整。<br>在路徑後面多加<strong>/:參數名稱，</strong>讓路由知道路徑中會包含參數。</p><p>以下是設定路徑最後會包含一個名為title的參數。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Deox-5P-unm6OEdc5I49CQ.png" /><figcaption>src/router/index.js</figcaption></figure><h4>matched path</h4><p>開啟src/Layout.vue，將&lt;router-link/&gt;的to屬性作調整，在原本的路徑後方加上<strong>/&quot;想傳入的參數值&quot;。</strong></p><p>以下是分別設定參數為<strong>連結1</strong>、<strong>連結2</strong>、<strong>連結3</strong>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zCSYjDqitgvoEDsbt4P-WQ.png" /><figcaption>src/Layout.vue</figcaption></figure><h4>$route.params</h4><p>開啟src/views資料夾底下的Nav1.vue、Nav2.vue、Nav3.vue。<br>調整以{{ $route.params.title }}，來抓取路徑中的title參數並顯示。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiVootAiFF6O3U0nwI7k4g.png" /><figcaption>src/views/Nav1.vue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9FyNtbbBNK9Pm_iVdaAkA.png" /><figcaption>src/views/Nav2.vue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9kvkEKi8e9nfRHUBmFwCLQ.png" /><figcaption>src/views/Nav3.vue</figcaption></figure><p>執行後，點選連結即可看到調整後的內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*icepjcMxRVwTWIRJiYdkVw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63b9edb0a5f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/vue-js-%E8%B7%AF%E7%94%B1-vue-router-63b9edb0a5f1">[ Vue.js ] 路由 : Vue Router</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[出版目錄]]></title>
            <link>https://medium.com/selectprogram/contents-4288e3f500c8?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4288e3f500c8</guid>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sat, 10 Jul 2021 14:25:33 GMT</pubDate>
            <atom:updated>2021-08-15T01:38:45.452Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*eR0pe7Y-YFwzNNa3M7etyw.png" /></figure><h3>.NET</h3><h4><a href="https://medium.com/selectprogram/asp-net-core%E4%BD%BF%E7%94%A8jwt%E9%A9%97%E8%AD%89-1b0609e6e8e3?source=collection_detail----1829c6d9c9f0-----1-----------------------">ASP.NET Core使用JWT驗證</a></h4><h4><a href="https://medium.com/selectprogram/asp-net-core-5-0-restful-api-16a6e3c60ba7?source=collection_detail----1829c6d9c9f0-----2-----------------------">ASP.NET Core 5.0 : RESTful API</a></h4><h4><a href="https://medium.com/selectprogram/asp-net-core-%E4%BD%BF%E7%94%A8-database-first-75c0c909a92c?source=collection_detail----1829c6d9c9f0-----4-----------------------">ASP.NET Core 使用 Database-First</a></h4><h4><a href="https://medium.com/selectprogram/input-type-file-%E6%AA%94%E6%A1%88%E4%B8%8A%E5%82%B3-%E5%89%8D%E5%BE%8C%E7%AB%AF%E6%AA%A2%E6%A0%B8%E5%89%AF%E6%AA%94%E5%90%8D-cf3cea90cad0?source=collection_detail----1829c6d9c9f0-----5-----------------------">Often Misused : &lt;input type=”file”&gt; 前後端檢核上傳檔案副檔名</a></h4><h4><a href="https://medium.com/selectprogram/c-npoi-%E4%B8%8A%E5%82%B3excel%E6%AA%94%E6%A1%88-%E4%B8%A6%E6%96%B0%E5%A2%9E%E8%87%B3%E8%B3%87%E6%96%99%E5%BA%AB-3fd6da9bb439?source=collection_detail----1829c6d9c9f0-----6-----------------------">C# NPOI 上傳Excel檔案，並新增至資料庫</a></h4><h4><a href="https://medium.com/selectprogram/asp-net-mvc%E4%BD%BF%E7%94%A8ssrs%E5%A0%B1%E8%A1%A8-d763eb7fb16b?source=collection_detail----1829c6d9c9f0-----7-----------------------">ASP.NET MVC使用SSRS報表</a></h4><h4><a href="https://medium.com/selectprogram/sql-server-reporting-services-94a79022e769?source=collection_detail----1829c6d9c9f0-----8-----------------------">SQL Server Reporting Servicesr建置流程</a></h4><h4><a href="https://medium.com/selectprogram/autofac%E7%AD%86%E8%A8%98-7485db8f5dac?source=collection_detail----1829c6d9c9f0-----9-----------------------">Autofac筆記</a></h4><h4><a href="https://medium.com/selectprogram/%E4%BD%BF%E7%94%A8rsa-%E9%87%91%E9%91%B0%E5%B0%8Dweb-config%E8%B3%87%E6%96%99%E5%BA%AB%E9%80%A3%E7%B7%9A%E5%AD%97%E4%B8%B2%E5%8A%A0%E5%AF%86-19f2b66d7a?source=collection_detail----1829c6d9c9f0-----10-----------------------">RSA 金鑰對Web.config資料庫連線字串加密</a></h4><h3>SQL</h3><h4><a href="https://medium.com/selectprogram/postgresql-error-could-not-open-file-for-writing-permission-denied-you-may-want-a-b7128ca79ac">[ PostgreSQL ] Error : could not open file for writing:Permission denied ; You may want a client-side facility such as psql’s \copy</a></h4><h4><a href="https://medium.com/selectprogram/sql-server%E8%B3%87%E6%96%99%E8%A1%A8%E5%88%86%E5%89%B2-table-partitioning-50698e5fb56">SQL Server資料表分割: Table Partitioning</a></h4><h4><a href="https://medium.com/selectprogram/postgresql-stored-procedure-81296e5d44e7?source=collection_detail----1829c6d9c9f0-----3-----------------------">PostgreSQL : Stored Procedure</a></h4><h3>FRONT-END</h3><h4><a href="https://medium.com/selectprogram/vue-js-%E5%85%83%E4%BB%B6-components-49494d53f316">[ Vue.js ] 元件: Components</a></h4><h4><a href="https://medium.com/selectprogram/vue-js-vue%E6%8C%87%E4%BB%A4-v-bind-fca1937d205c">[ Vue.js ] Vue指令: v-bind</a></h4><h4><a href="https://medium.com/selectprogram/vue-js-%E8%B3%87%E6%96%99%E7%B6%81%E5%AE%9A-data-71a359548952?source=collection_detail----1829c6d9c9f0-----0-----------------------">[ Vue.js ] 資料綁定: Data</a></h4><h4><a href="https://medium.com/selectprogram/vue-js-%E8%B7%AF%E7%94%B1-vue-router-63b9edb0a5f1">[ Vue.js ] 路由 : Vue Router</a></h4><h4><a href="https://medium.com/selectprogram/vue-js-%E5%B0%88%E6%A1%88%E7%B5%90%E6%A7%8B-3668dda87b70">[ Vue.js ] 專案結構</a></h4><h4><a href="https://medium.com/selectprogram/vue-js-%E5%BB%BA%E7%AB%8Bvue%E5%B0%88%E6%A1%88-aa37b64c9bc5?source=collection_detail----1829c6d9c9f0-----0-----------------------">[ Vue.js ] 建立Vue專案</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4288e3f500c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/contents-4288e3f500c8">出版目錄</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Server資料表分割: Table Partitioning]]></title>
            <link>https://medium.com/selectprogram/sql-server%E8%B3%87%E6%96%99%E8%A1%A8%E5%88%86%E5%89%B2-table-partitioning-50698e5fb56?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/50698e5fb56</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[partition]]></category>
            <category><![CDATA[sql-server]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sat, 10 Jul 2021 14:14:11 GMT</pubDate>
            <atom:updated>2021-07-17T05:29:00.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*bQwbp7qYHfbsTVyfHdN55A.jpeg" /></figure><p>Table Partitioning，將資料龐大的Table依照指定的區塊切分為數個小Table，讓查詢Table時只會從特定區間內的小Table去抓資料，減少資料庫搜尋整張Table的時間與效能。<br>後記:新增切割範與MERGE RANGE。</p><h3>Table Partitioning步驟</h3><ul><li>建立檔案群組</li><li>新增檔案至群組</li><li>建立Partition Function(分割範圍)</li><li>建立 Partition Schema(依檔案群組)</li><li>建立要分割的資料表</li></ul><blockquote><strong><em>建立檔案群組</em></strong></blockquote><p>在資料庫建立檔案群組，將群組以年度做區分，建立FileGroup_2015~FileGroup_2021。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddf24c1a4567dc17abd8ba4fdb56e1e7/href">https://medium.com/media/ddf24c1a4567dc17abd8ba4fdb56e1e7/href</a></iframe><blockquote><strong><em>新增檔案至群組</em></strong></blockquote><p>在每個檔案群組中加入檔案做儲存。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97426ab9e508c40384a2594efaa3be58/href">https://medium.com/media/97426ab9e508c40384a2594efaa3be58/href</a></iframe><p>完成後，在<strong>物件總管</strong>&gt;資料庫點<strong>右鍵</strong>&gt;選擇<strong>屬性</strong>，在資料庫屬性的檔案群組中可看到剛剛新增的群組及檔案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4wgJkhqp91_q2YUFGMlcw.png" /><figcaption><strong>物件總管</strong>&gt;資料庫點<strong>右鍵</strong>&gt;選擇<strong>屬性</strong>，資料庫屬性中新增的群組及檔案。</figcaption></figure><blockquote><strong><em>建立Partition Function(分割範圍)</em></strong></blockquote><p>建立Function，依年分切割成2015年~2021年的區間。<br>RANGE RIGHT: 表示臨界值的資料會是屬於右邊的區塊。<br>RANGE LEFT: 表示臨界值的資料會是屬於左邊的區塊。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64f36471b0938cefaae89ded4f4cba98/href">https://medium.com/media/64f36471b0938cefaae89ded4f4cba98/href</a></iframe><blockquote><strong><em>建立 Partition Schema(依檔案群組)</em></strong></blockquote><p>建立Schema，指定存放分割後區塊的資料。<br>最後一個Primary為預留，當有資料超出切割範圍(2015~2021年)，會存放於Primary中。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42db18e3733ac0f395bfea44cfbc0e52/href">https://medium.com/media/42db18e3733ac0f395bfea44cfbc0e52/href</a></iframe><blockquote><strong><em>建立要分割的資料表</em></strong></blockquote><p>建立資料表，並指定欄位「訂單日期(order_date)」依照Partition Schema(ParSch_Year)做分割。<br>如Table有設定主鍵(Primary Key)，則分割欄位也必須是主鍵之一。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a137412cf54eec0fb7882911d97479b/href">https://medium.com/media/6a137412cf54eec0fb7882911d97479b/href</a></iframe><blockquote><strong><em>查詢系統資料表</em></strong></blockquote><p>查看資料分割至不同區塊的筆數統計。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40d7a5eed2e5efaf11ed07e3bcd6dc52/href">https://medium.com/media/40d7a5eed2e5efaf11ed07e3bcd6dc52/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*Z2RBvqr3jbuRx1Ht5MDZmQ.png" /></figure><blockquote><strong><em>後記</em></strong></blockquote><p>新增切割範圍</p><pre>— 指定下個新分割區要使用的檔案群組<br>ALTER PARTITION SCHEME <strong>PartitionSchema名稱</strong> NEXT USED <strong>[檔案群組]</strong>;</pre><pre>--建立新的分割區<br>ALTER PARTITION FUNCTION <strong>PartitionFunction名稱</strong> SPLIT RANGE (<strong>切割的值</strong>);</pre><p><strong>Example :<br></strong> ALTER PARTITION SCHEME ParSch_Year NEXT USED [FileGroup_2022];</p><p>ALTER PARTITION FUNCTION ParFun_Year SPLIT RANGE (&#39;2022–12–31 00:00:00:.000&#39;);</p><p>刪除特定分割區資料</p><pre>TRUNCATE TABLE <strong>資料表名稱</strong> WITH(Partitions(<strong>sys.partitions的partition_number欄位</strong>))</pre><p><strong>Example :</strong> <br>TRUNCATE TABLE orderlist WITH(Partitions(&quot;1&quot;))</p><p>Merge分割區</p><pre>ALTER PARTITION FUNCTION <strong>PartitionFunction名稱</strong> MERGE RANGE (<strong>切割的值</strong>)</pre><p><strong>Example : <br></strong>ALTER PARTITION FUNCTION ParFun_Year MERGE RANGE (&#39;2015–12–31 00:00:00.000&#39;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50698e5fb56" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/sql-server%E8%B3%87%E6%96%99%E8%A1%A8%E5%88%86%E5%89%B2-table-partitioning-50698e5fb56">SQL Server資料表分割: Table Partitioning</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[ Vue.js ] 專案結構]]></title>
            <link>https://medium.com/selectprogram/vue-js-%E5%B0%88%E6%A1%88%E7%B5%90%E6%A7%8B-3668dda87b70?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3668dda87b70</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sat, 10 Jul 2021 14:07:55 GMT</pubDate>
            <atom:updated>2021-07-18T08:30:44.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*h7pchhtcDa0lEIJzpdr-4w.png" /></figure><p>Vue專案結構巡覽。<br>Vue檔案中的組成架構 : template、script、style。</p><blockquote><strong><em>專案結構</em></strong></blockquote><p><a href="https://medium.com/selectprogram/vue-js-%E5%BB%BA%E7%AB%8Bvue%E5%B0%88%E6%A1%88-aa37b64c9bc5?source=collection_home---4------1-----------------------"><strong>建立完Vue專案</strong></a>後，開啟專案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5Je9xcD27-Yb19z-3NOCQ.png" /><figcaption>專案</figcaption></figure><p>可以看到src資料夾(Vue 專案的核心)底下，分別為assets與components資料夾、App.vue與main.js檔案。</p><p><strong>assets資料夾 : </strong>放置一些靜態圖片與CSS。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PBa9OqvmRrMcdaBJaH4IfQ.png" /><figcaption>src/assets/logo.png</figcaption></figure><p><strong>components資料夾 : </strong>放置共用元件。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Lr_sNTy3BVFZgCdWGmt-w.png" /><figcaption>src/components/HelloWorld.vue</figcaption></figure><p><strong>App.vue : </strong>Vue應用程式的根節點。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aTZ6g9NT6vn3RuoGGf-hKA.png" /><figcaption>src/App.vue</figcaption></figure><p><strong>main.js : </strong>專案入口處，初始化 Vue 應用程式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_M3l70V5--FXgYaMucTyA.png" /><figcaption>src/main.js</figcaption></figure><blockquote><strong><em>App.vue</em></strong></blockquote><p>開啟App.vue檔案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJkFyCf4rxj_vegfAPdNSg.png" /><figcaption>src/App.vue</figcaption></figure><p>.vue檔案主要是由三個標籤所組成的，以App.vue的內容依序來看，分別為<br><strong>template</strong>、<strong>script</strong>、<strong>style。</strong></p><blockquote><strong><em>script</em></strong></blockquote><pre>&lt;script&gt;區塊是註冊元件與處理Javascript的區域。</pre><p>在script中，會創建一個vue的實體，並用<strong>export default { ...};</strong>包著來輸出給template或是其他外部做引入使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*uUBPi0-DcHSLmd9G0pggfg.png" /></figure><p>vue元件操作:</p><h4>[ components ]</h4><p>定義元件(components)。</p><p>在專案的src/App.vue，可以看到&lt;script/&gt;中的第一行import HelloWorld from &quot;./components/HelloWorld.vue&quot;;import(引入)HelloWorld.vue檔案並命名為HelloWorld。<br>接著在export default { …};中，將HelloWorld以元件(components)輸出至頁面，讓&lt;template/&gt;以&lt;HelloWorld&gt;標籤來做使用，顯示HelloWorld.vue中的內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*ZB43t8hT0t3OyH0cmZ98ew.png" /><figcaption>src/App.vue的&lt;script&gt;</figcaption></figure><h4><strong>[ props ]</strong></h4><p>元件(components)與元件(components)之前傳遞資料的方式。</p><p>在專案的src/HelloWorld.vue，可以看到&lt;script/&gt;的export default { }內定義了props屬性有一個命名為msg、型態為String的組件。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*pUlbLEqv6XxqXX3AMGMbPg.png" /><figcaption>src/HelloWorld.vue的&lt;script&gt;</figcaption></figure><p>接著在src/HelloWorld.vue，往上看到&lt;template/&gt;內&lt;h1&gt;{{ msg }}&lt;/h1&gt;<br>以花括號包住msg來顯示接收到的msg值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*XsQ0efFlsoYidL00-6JVRw.png" /><figcaption>src/HelloWorld.vue的&lt;template&gt;</figcaption></figure><p>其他還有很多元件，如:data ()、computed、methods、watch、filters、directives...等，用來定資料或是計算、處理資料。</p><blockquote><strong><em>template</em></strong></blockquote><pre>&lt;template&gt;區塊是元件模板，主要是處理HTML與Vue的語法。</pre><p>&lt;img&gt;標籤定義了圖片來源為assets裡的logo.png圖檔，並顯示在畫面上。&lt;Helloworld/&gt;標籤顯示Helloworld.vue的內容<strong>。</strong></p><p>template翻譯成中文為模板，&lt;template&gt;標籤內是用來撰寫HTML的地方，比較特別的是這邊除了可以寫HTML外，還可以操作Vue的語法。</p><p>template中的Vue語法操作，如src/HelloWorld.vue中以花括號{{ }}顯示值的方式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*XsQ0efFlsoYidL00-6JVRw.png" /><figcaption>src/HelloWorld.vue的&lt;template&gt;</figcaption></figure><p>其他還有很多Vue語法，如:v-for、v-if、v-else-if、v-else、v-show、…等，用來組成HTML畫面。</p><blockquote><strong><em>style</em></strong></blockquote><p><strong>&lt;style&gt;區塊</strong>設定頁面的CSS樣式。</p><p>跟一般寫CSS的寫法一樣，其中比較特別的是scoped屬性。<br>在style加上scoped屬性後，裡面所寫的CSS樣式會變成僅限於這個vue元件使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*4hxAkWvOCOTw4Zy_sJ14qQ.png" /><figcaption>src/App.vue的&lt;template&gt;</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3668dda87b70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/vue-js-%E5%B0%88%E6%A1%88%E7%B5%90%E6%A7%8B-3668dda87b70">[ Vue.js ] 專案結構</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[PostgreSQL] Error : could not open file for writing:Permission denied ; You may want a…]]></title>
            <link>https://medium.com/selectprogram/postgresql-error-could-not-open-file-for-writing-permission-denied-you-may-want-a-b7128ca79ac?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7128ca79ac</guid>
            <category><![CDATA[export]]></category>
            <category><![CDATA[psql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Thu, 01 Jul 2021 01:17:13 GMT</pubDate>
            <atom:updated>2021-07-10T14:08:50.188Z</atom:updated>
            <content:encoded><![CDATA[<h3>[PostgreSQL] Error : could not open file for writing:Permission denied ; You may want a client-side facility such as psql’s \copy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y510alhRO4oXqUyS8gRZ7w.jpeg" /></figure><p>PostgreSQL執行copy語法要Export匯出時，出現以下錯誤訊息的解決方法。<br><strong>ERROR : could not open file “xxxx” for writing:Permission denied <br>HINT : Copy To instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql’s \copy</strong></p><blockquote><strong><em>事情緣由</em></strong></blockquote><p>輸入匯出資料語法:</p><pre>copy (select * from TableName) To &#39;C:\file.csv&#39; delimiter &#39;,&#39; csv HEADER ENCODING &#39;UTF8&#39;</pre><p>出現錯誤訊息: 顯示不被允許開啟檔案。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bCv_ZH26Ityg4TxznH-O3w.png" /></figure><blockquote><strong><em>解決方法</em></strong></blockquote><p>一.檔案不要放在C槽。</p><p>二.使用SQL Shell( psql)執行。</p><p>開啟PostgreSQL的SQL Shell。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*HPbofceqSMHgHDul4ZmgIQ.png" /></figure><p>連線至Server後，執行以下語法，即可匯出。</p><pre>\copy (select * from TableName) To &#39;C:\file.csv&#39; delimiter &#39;,&#39; csv HEADER ENCODING &#39;UTF8&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*oG4wfssxzi-mug1czDhyvA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7128ca79ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/postgresql-error-could-not-open-file-for-writing-permission-denied-you-may-want-a-b7128ca79ac">[PostgreSQL] Error : could not open file for writing:Permission denied ; You may want a…</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[ Vue.js ] 建立Vue專案]]></title>
            <link>https://medium.com/selectprogram/vue-js-%E5%BB%BA%E7%AB%8Bvue%E5%B0%88%E6%A1%88-aa37b64c9bc5?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa37b64c9bc5</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 11:00:10 GMT</pubDate>
            <atom:updated>2021-07-11T07:17:28.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*Vv37sJpaP72DjEuvkQak6w.png" /></figure><p>使用Visual Studio Code。<br>安裝Node.js後，以npm安裝Vue CLI來建立Vue專案。</p><h4>步驟</h4><ul><li>安裝Node.js</li><li>npm 安裝Vue CLI</li><li>Vue CLI 建立一個Vue專案</li></ul><blockquote><strong><em>安裝Node.js</em></strong></blockquote><pre>在安裝 Vue CLI 之前，必須先安裝 Node.js與npm。</pre><h3>Node.js</h3><p>Node.js 是能夠在伺服器端運行 JavaScript 的開放原始碼、跨平台執行環境。<br>可以在Node.js官網下載: <a href="https://nodejs.org/en/">https://nodejs.org/en/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50v4AoFuKNYPY_m9Nw84mg.png" /><figcaption>LTS為穩定版 Current為最新版</figcaption></figure><p>下載完安裝檔後，就Next到安裝完成即可。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*ClR1eZLW6zoRg_064Cv7Qg.png" /><figcaption>Finish</figcaption></figure><h3>npm</h3><p>npm（全稱 Node Package Manager，即「node包管理器」），是由JavaScript編寫的軟體套件管理系統，可以讓使用者輕鬆下載其他的套件(package)或模組(module)，npm會隨著Node.js自動安裝。</p><h4>Visual Studio Code</h4><p>若要確認版本與更新版本，可以在開啟 Terminal 終端機下指令。</p><p>選擇檔案→喜好設定→設定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2KHyNZDSKUweTl0I6b4eFw.png" /></figure><p>功能→終端機→Integrated › Default Profile: Windows選擇Git Bash。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBstzkGdNHtDaAusRBYJog.png" /></figure><p>終端機輸入:<br><strong> node --version </strong><br>若終端機回覆版本號，則表示Node.js安裝成功。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bl6ZM0lE1fZHF156Ww3fvQ.png" /></figure><p>終端機輸入:<br><strong> npm --version </strong><br>終端機會回覆npm版本。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paB-bwVrgtrgKLIgqExggg.png" /></figure><p>終端機輸入:<br><strong> npm update -g npm <br></strong>更新npm。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F-AELtfHlVsP0oYkLDp68w.png" /></figure><blockquote><strong><em>npm 安裝Vue CLI</em></strong></blockquote><pre>透過npm全域安裝vue-cli，安裝完後即可使用vue指令。</pre><p>終端機輸入:<br><strong> npm install -g @vue/cli<br></strong> 安裝Vue CLI。</p><p>等待一陣子，待vue-cli安裝完畢。</p><p>終端機輸入:<br><strong> vue --version<br></strong>終端機會回覆Vue CLI版本<strong>@vue/cli 4.5.13</strong>，即表示安裝成功。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2C2TjyDARX0EfUBsoyhAqA.png" /></figure><blockquote><strong><em>Vue CLI 建立一個Vue專案</em></strong></blockquote><pre>終端機使用Vue CLI建立Vue專案。</pre><p>終端機輸入:<br><strong> vue create [專案名稱]<br></strong>這邊我輸入<strong> vue create vue_project</strong>，建立一個名叫<strong>vue_project</strong>的專案。</p><p>接著會看到畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUJkR_IotvEYphTjL8Mu4Q.png" /></figure><p>選擇Vue的版本(相關套件預設會一併安裝babel與eslint)，若這邊選擇Manually select features，可以再自行選擇其他想一併安裝的套件。</p><p>這邊我選擇Manually select features，Enter下一步:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8V5A3pl6uAzdOt9sfrtag.png" /></figure><p>可以看到說明，按下<strong>空白鍵</strong>是選擇，按下<strong>a</strong>是全選，<strong>i</strong>擇是反選擇(改選為目前未勾選的項目)。</p><p>勾選完想一併安裝的套件後，在<strong>Choose Vue version</strong>選項按下Enter，選擇Vue版本:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9cxcmdVyuWzlSBTCaBhTvA.png" /></figure><p>選擇ESLint風格:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ii-dp9hUMKqRO330HRTWEA.png" /></figure><p>Lint檢查程式碼的時機:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBSgDpPexfHJbvGzADwrQA.png" /></figure><p>Babel, PostCSS, ESLint ...等等的Config檔放置位子，多數情況下會放在 package.json 統一管理:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGn2iRQSKA7e-PbE1emUqQ.png" /></figure><p>將以上設定設為之後專案的預設選項:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z7mx2b203cvasW_fNq7qfA.png" /></figure><p>儲存預設:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqgDIRnK0vNOCjY2zaOZSg.png" /></figure><p>接下來會開始建立專案，建立完成的畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G6AEUVGH82aGX_tSvqWt6A.png" /></figure><p>終端機輸入<br><strong>cd vue_project<br></strong>切換目錄到剛剛建立的專案資料夾。</p><p>再輸入<br><strong>npm run serve<br></strong>(若顯示&quot;node&quot;不是內部或外部命令、可執行的程式或批次檔。<br>則在本機右鍵→內容→進階系統設定→進階→環境變數→Path→新增Node.js所安裝的位置，ex:C:\Program Files\nodejs)<br>啟動專案，會看到以下畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IVZLnXtLDLS2K1pVCVpOsw.png" /></figure><p>在瀏覽器輸入上面的連結 http://localhost:8083/即可看到執行的專案畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M7UlU9fbvV2PnbskcBE1xQ.png" /></figure><p>直接開啟資料夾，也能看到建立好的專案:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_sihaqdAc_jWV1zg02aLyw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa37b64c9bc5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/vue-js-%E5%BB%BA%E7%AB%8Bvue%E5%B0%88%E6%A1%88-aa37b64c9bc5">[ Vue.js ] 建立Vue專案</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASP.NET Core使用JWT驗證]]></title>
            <link>https://medium.com/selectprogram/asp-net-core%E4%BD%BF%E7%94%A8jwt%E9%A9%97%E8%AD%89-1b0609e6e8e3?source=rss-7bd36933997e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b0609e6e8e3</guid>
            <category><![CDATA[jwt-auth]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[dot-net-core]]></category>
            <category><![CDATA[dot-net-framework]]></category>
            <dc:creator><![CDATA[Select *]]></dc:creator>
            <pubDate>Sun, 27 Jun 2021 01:37:07 GMT</pubDate>
            <atom:updated>2021-09-02T05:57:40.478Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-2u9ILj1hj7FJIZ8roieA.jpeg" /></figure><p>JWT(JSON Web Tokens)是一種開放、標準的 RFC 7519 方法，用於在兩方之間以JSON物件安全的傳遞訊息。<br>本篇將以ASP.NET Core 5.0設定JWT的驗證，以及產生Token與刷新Token，並在呼叫API的時候驗證Token是否有效。<br>最後，以HttpClient呼叫API與驗證Bearer Token。</p><blockquote><strong><em>JWT的組成</em></strong></blockquote><p>JWT是由三組JSON物件Header、Payload與Signature所組成，這三組JSON物件會各自編碼，物件之間以<strong>.</strong>做區隔組成一串Token字串。<br>組合成如<strong>Header.Payload.Signature</strong>的字串。</p><p>實際組成的JWT會如下顯示:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*quR8gDEHfE_eB_HFCz8twA.png" /><figcaption>JWT演示</figcaption></figure><h4><strong>Header</strong></h4><p>由&quot;alg&quot;與&quot;typ&quot;兩個欄位組成。<br><strong>alg( algorithm): </strong>token加密的演算法，如HMAC、SHA256、RSA。<br><strong>typ( type):</strong> token的類型，基本上就是 JWT。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*EiJJdaumbS5mKmTZ_JLT_Q.png" /><figcaption>Header演示</figcaption></figure><h4>Payload</h4><p>這裡放的是聲明 (Claim) 內容，也就是用來放傳遞訊息的地方。<br>JWT 標準公定的Registered claims有七種。</p><ul><li>iss (issuer)：簽發人</li><li>exp (expiration time)：過期時間</li><li>sub (subject)：主題</li><li>aud (audience)：接收人</li><li>nbf (Not Before)：開始生效時間</li><li>iat (Issued At)：簽發時間</li><li>jti (JWT ID)：編號， JWT 的 Id</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*Z3SSXv99iel1a_yHhLmdXQ.png" /><figcaption>Payload演示</figcaption></figure><p>因為 Payload 傳遞的訊息最後也是透過 Base64 進行編碼，所以是可以被破解的，所以放在Payload的訊息必須為公開、比較不機密的資訊。</p><h4>Signature</h4><p>由三部分組成:</p><ul><li>以Base64 編碼的Header</li><li>以Base64 編碼的Payload</li><li>secret(密鑰)</li></ul><p>Header跟 Payload中間用<strong>.</strong>來串接，secret 是存放在伺服器端的秘密字串，最後將這三個部分串接在一起的字串，以Header定義的演算法進行加密。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*O_oogoOxSptpOTlSlPiAMg.png" /><figcaption>Signature演示</figcaption></figure><p>下圖為整個Token產生的流程圖:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bh6cFshpLMsk2rhvYIJfDg.png" /><figcaption>JWT Token產生流程圖</figcaption></figure><blockquote><strong><em>JWT實作</em></strong></blockquote><pre><strong>以ASP.NET Core 5.0的RESTful API來實作JWT，包含登入驗證、產生Token、驗證Token與Token刷新。</strong></pre><p>專案採用<a href="https://medium.com/selectprogram/asp-net-core-5-0-restful-api-16a6e3c60ba7"><strong>這裡</strong></a>延續撰寫。<br>以專案中的API套用JWT驗證機制，來驗證訪問token是否有權限。</p><p>會使用到的資料表有三個:</p><p>Users資料表:用來儲存使用者帳號密碼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*NF7iEGg1DCRIIPxbctdngg.png" /></figure><p>UserToken資料表:用來儲存Token與RefreshToken。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*VwwQ5ZdALVgvmPF8BT67AA.png" /></figure><p>OrderList資料表:驗證後查詢的資料。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*aG97sr0i5Vq39oHkSBkNiA.png" /></figure><h4><strong>實作步驟</strong></h4><ol><li>設定JWT Token驗證</li><li>建立產生JWT Token的方法</li><li>建立RefreshToken的機制</li><li>呼叫API產生Token與驗證</li><li>HttpClient呼叫API</li></ol><blockquote><strong><em>設定JWT Token驗證</em></strong></blockquote><pre>設定JWT Token的密鑰與註冊驗證的服務。</pre><h4><strong>NuGet下載套件</strong></h4><pre><strong>Microsoft.AspNetCore.Authentication.JwtBearer <br>Microsoft.AspNetCore.Identity.EntityFrameworkCore <br>Microsoft.AspNetCore.Identity.UI</strong></pre><h4><strong>appsettings.json</strong></h4><p>在appsettings.json中加入JWT的section &quot;JwtConfig&quot;與JWT的密鑰 &quot;Secret&quot;。</p><pre>&quot;JwtConfig&quot;: {<br>&quot;Secret&quot;: &quot;rdqziegmbzhflvkjpvhuadenwoxgpabu&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFCpI_nV2l__-YSUhLVmRg.png" /><figcaption>這邊可以使用工具來產生隨機的32位數字串當作密鑰。<br>(<a href="https://www.browserling.com/tools/random-string">https://www.browserling.com/tools/random-string</a>)</figcaption></figure><h4><strong>建立密鑰</strong></h4><p>在專案中新增Configuration資料夾，並新增JwtConfig Class。<br>用來接收傳遞Secret密鑰。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XeM_n6Buti36ka-T84dk-g.png" /></figure><h4><strong>Startup設定</strong></h4><p>在Startup.cs的ConfigureServices方法中，加入以下程式碼。<br>之後在程式中注入JwtConfig，即可取得&quot;appsettings.json&quot;中的&quot;JwtConfig&quot;的值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*zImoT-FMvyxi1_JtibFOpg.png" /></figure><p>接著，繼續在Startup.cs的ConfigureServices方法中，新增驗證配置。<br>建立TokenValidationParameters，用來驗證客戶端傳過來的token是否合法。並透過AddAuthentication註冊驗證的服務，並設定JWT的驗證配置。</p><p>ConfigureServices方法的詳細程式碼如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c363a6ebb685f412f1d57a67d98b984b/href">https://medium.com/media/c363a6ebb685f412f1d57a67d98b984b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Onazs_7grLLMfokTUCAmJw.png" /><figcaption>Startup.cs/ConfigureServices()</figcaption></figure><p>然後，在Startup.cs的Configure方法中，app.UseAuthorization()授權之前加入app.UseAuthentication()識別身分。<br>這樣才能在授權之前，先驗證是否為有效的身分。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTlSry915nIQOPhV3sw1NA.png" /><figcaption>Startup.cs/Configure()</figcaption></figure><h4><strong>ASP.NET Core 中的授權</strong></h4><p>ASP.NET Core 中的授權是由 <a href="https://docs.microsoft.com/zh-tw/dotnet/api/microsoft.aspnetcore.authorization.authorizeattribute">AuthorizeAttribute</a> 和其各種參數所控制。 在其最基本的表單中，將 [Authorize] 屬性套用至控制器、動作或 Razor 頁面，會限制對該元件已驗證使用者的存取。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jKOC2-M_Lu09ymdlBpxSZg.png" /><figcaption>在API接口加入[Authorize]篩選器，限制呼叫時須透過驗證機制。</figcaption></figure><p>也可以使用 AllowAnonymous 屬性來允許未經驗證的使用者存取個別動作。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZKydDlj5cPBo_yVpuqW43A.png" /><figcaption>在API接口加入[AllowAnonymous]篩選器，不用驗證也能呼叫</figcaption></figure><blockquote><strong><em>建立產生JWT Token的方法</em></strong></blockquote><pre>新增Mehod來檢核登入帳號，並產生JWT Token。</pre><h4><strong>建立驗證的回傳訊息</strong></h4><p>在Configuration資料夾中，建立新class命名AuthResult，用來回覆驗證後的訊息。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSiSLmMGxFT57Hs1jwrW0A.png" /><figcaption>Configuration/AuthResult.cs</figcaption></figure><h4><strong>建立DTO</strong></h4><p>建立DTO(data transfer objects)，在Models資料夾裡新增DTOs資料夾。<br>並在DTOs資料夾中新增兩個資料夾Requests跟Responses。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ui9jCayFMzHeMS1CVAxoCg.png" /><figcaption>Models/DTOs</figcaption></figure><p>在Models/DTOs/Requests中，新增UserLoginRequest.cs，做為登入的Request。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3k2UDL7zREptVhCu-A7ceg.png" /><figcaption>Models/DTOs/Requests/UserLoginRequest.cs</figcaption></figure><p>在Models/DTOs/Response中，新增UserLoginResponse.cs，並直接繼承AuthResult.cs。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*879OG_k5GlmuvIZoPIOqHg.png" /><figcaption>Models/DTOs/Response/UserLoginResponse.cs</figcaption></figure><h4><strong>AuthManagementController</strong></h4><p>在Controllers資料夾中，新增AuthManagementController.cs，並注入JwtConfig與MyDBContext。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_MN_V5ljWplwb40MrqTyw.png" /><figcaption>Controllers/AuthManagementController.cs</figcaption></figure><h4><strong>新增Method來產生JWT Token</strong></h4><p>新增GenerateJwtToken方法，用來產生JWT Token。</p><p>程式碼如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8b4d7fb8c9054ca6a9222d65bc516bf/href">https://medium.com/media/b8b4d7fb8c9054ca6a9222d65bc516bf/href</a></iframe><h4><strong>新增Method做為登入用</strong></h4><p>新增Login方法，做為登入的API接口。在驗證帳號、密碼後，呼叫GenerateJwtToken方法產生JWT Token並回傳資訊。</p><p>程式碼如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/348ab8f350ab8c69b86fc45b1955986b/href">https://medium.com/media/348ab8f350ab8c69b86fc45b1955986b/href</a></iframe><blockquote><strong><em>建立RefreshToken的機制</em></strong></blockquote><pre>新增Mehod，驗證Token與RefreshToken後，建立新的Token並回傳。</pre><h4><strong>建立DTO</strong></h4><p>Models/DTOs/Requests新增TokenRequest.cs，做為刷新token的Request。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpoouigMP7iPNJT-bYxBtw.png" /><figcaption>Models/DTOs/Requests/TokenRequest.cs</figcaption></figure><h4><strong>AuthManagementController</strong></h4><p>注入TokenValidationParameters。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyca73HLEsO6O4lj-MFbFQ.png" /><figcaption>AuthManagementController.cs</figcaption></figure><h4><strong>新增Method驗證並重新產生Token</strong></h4><p>新增VerifyAndGenerateToken方法，在驗證Token參數後，呼叫GenerateJwtToken方法，產生新Token並回傳。</p><p>程式碼如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7562f7ba9cf300f901ac9a00a614db8/href">https://medium.com/media/e7562f7ba9cf300f901ac9a00a614db8/href</a></iframe><h4><strong>新增Method做為刷新Token用</strong></h4><p>新增RefreshToken方法，做為刷新Token的API接口。<br>呼叫VerifyAndGenerateToken方法來驗證輸入的Token參數與回傳刷新的Token。</p><p>程式碼如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a97b7d2deaf0062c770557c0e0f2b811/href">https://medium.com/media/a97b7d2deaf0062c770557c0e0f2b811/href</a></iframe><blockquote><strong><em>呼叫API產生Token與驗證</em></strong></blockquote><p>執行傳案後，以Postman呼叫/api/AuthManagement/Login，來登入並取得Token與RefreshToken。</p><p>Body內容為:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*reZKgVzB04ukFENjhMDdZw.png" /></figure><p>執行畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DOoKKmJYaOR5bfzkmR_XJw.png" /></figure><p>若要刷新產生新的Token，呼叫/api/AuthManagement/RefreshToken，來刷新Token。</p><p>執行畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckimRMuTOUwCjnlOq2RoXA.png" /></figure><p>呼叫掛有[Authorize]驗證的API，在Postman的Authorization中，選擇Tyep為Bearer Token，並輸入Token。</p><p>執行畫面:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqbXOI7c6-mohMTheKUK7Q.png" /></figure><blockquote><strong><em>HttpClient呼叫API</em></strong></blockquote><p>在C#中使用HttpClient呼叫API時，設定Header的驗證Token可使用:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRRuj6znWDSO8KXcfv9ICg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93bfa536849d5ab17f3ff55c7b65a68f/href">https://medium.com/media/93bfa536849d5ab17f3ff55c7b65a68f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b0609e6e8e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/selectprogram/asp-net-core%E4%BD%BF%E7%94%A8jwt%E9%A9%97%E8%AD%89-1b0609e6e8e3">ASP.NET Core使用JWT驗證</a> was originally published in <a href="https://medium.com/selectprogram">Program</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>