if (href) { result += `<a class="${className}-link" href="${href}">`; } else { result += `<a class="${className}-link">`; }
從這裡可以知道,href是由id作成的,而id是來自於el,el則是data的item
1 2 3 4 5 6
for (let i = 0, len = data.length; i < len; i++) { const el = data[i]; const { level, id, text } = el; const href = id ? `#${encodeURL(id)}` : null; //... }
我們試著把data Print出來,注意,不是在瀏覽器,而是在你的node terminal。
1 2 3 4 5 6 7
console.log(data) for (let i = 0, len = data.length; i < len; i++) { const el = data[i]; const { level, id, text } = el; const href = id ? `#${encodeURL(id)}` : null; //... }
<!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services --> <!-- Firebase App (the core Firebase SDK) is always required and must be listed first --> <scriptsrc="https://www.gstatic.com/firebasejs/8.2.5/firebase-app.js"></script>
<!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics --> <scriptsrc="https://www.gstatic.com/firebasejs/8.2.5/firebase-analytics.js"></script>
<!-- Add Firebase products that you want to use --> <scriptsrc="https://www.gstatic.com/firebasejs/8.2.5/firebase-auth.js"></script> <scriptsrc="https://www.gstatic.com/firebasejs/8.2.5/firebase-firestore.js"></script>
// The warn palette is optional (defaults to red). $candy-app-warn: mat-palette($mat-red);
// Create the theme object. A theme consists of configurations for individual // theming systems such as `color` or `typography`. $candy-app-theme: mat-light-theme(( color: ( primary: $candy-app-primary, accent: $candy-app-accent, warn: $candy-app-warn, ) ));
// Include theme styles for core and each component used in your app. // Alternatively, you can import and @include the theme mixins for each component // that you are using. @include angular-material-theme($candy-app-theme);
註: 若是出錯可參考以下解法: 修改webpack.config.js裡的__dirname為'dist',並將filename修改為'js/bundle.js'之後,再跑一次npm run start,就成功了。這是因為path要指向到dist裡的index.html,而非dist/js裡(這裡面沒有index.html)。