iT邦幫忙

0

Vue pro 屬性問題請教

  • 分享至 

  • xImage

您好:
參考
https://ithelp.ithome.com.tw/articles/10209687
會出現ERR

https://ithelp.ithome.com.tw/upload/images/20210502/20104095umKrkMzh0s.png
https://i.imgur.com/3RtFPjt.png

請問,傳入字串是指

這邊嗎? 我改成

一樣會出現ERR

   <div id="app">
        <counter start="10"></counter>
    </div>


    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
    <script>
        Vue.component('counter', {
            props: {
                start: Number,
            },
            template: `
                    <div>
                    <h1>{{count}}</h1>
                    <button @click="count+=1">按我</button>
                    </div>
                `,
            data() {
                return {
                    count: this.start,
                }
            }

        });

        new Vue({
            el: "#app"
        });
    </script>
改成這樣

<counter :start="10"></counter>

HTML的屬性都會被當作字串,所以前面加上冒號改用綁定的方式傳值
noway iT邦研究生 3 級 ‧ 2021-05-16 16:08:46 檢舉
謝謝您!
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
koro_michael
iT邦新手 2 級 ‧ 2021-05-03 00:02:49
最佳解答

改成這樣

<counter :start="10"></counter>

HTML的屬性都會被當作字串,所以前面加上冒號改用綁定的方式傳值

noway iT邦研究生 3 級 ‧ 2021-05-16 16:09:04 檢舉

謝謝您!

我要發表回答

立即登入回答