回答編集履歴
2
ソースコードを見つけたので追記
answer
CHANGED
@@ -5,4 +5,21 @@
|
|
5
5
|
定義が漏れている、依存関係が崩れている、などのことが起きていると思いますので、その部分を確認してみてください。
|
6
6
|
|
7
7
|
参考:
|
8
|
-
[Custom elements](https://ja.javascript.info/custom-elements)
|
8
|
+
[Custom elements](https://ja.javascript.info/custom-elements)
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
# ソースコードを見つけたので追記
|
13
|
+
|
14
|
+
[Dawnテーマのデモページ](https://themes.shopify.com/themes/dawn/styles/default/preview?locale=ja)のソースを見てきましたが、やはり独自タグを実装していて、そこで独自メソッドの`setActiveElement`を定義しているようです。
|
15
|
+
このCDNを読み込み忘れている、あるいは読み込み順序を間違えている、などの原因の可能性が高いです。
|
16
|
+
|
17
|
+
```js
|
18
|
+
class CartNotification extends HTMLElement{constructor(){super(),this.notification=document.getElementById("cart-notification"),this.header=document.querySelector("sticky-header"),this.onBodyClick=this.handleBodyClick.bind(this),this.notification.addEventListener("keyup",(t=>"Escape"===t.code&&this.close())),this.querySelectorAll('button[type="button"]').forEach((t=>t.addEventListener("click",this.close.bind(this))))}
|
19
|
+
|
20
|
+
/...
|
21
|
+
|
22
|
+
setActiveElement(t){this.activeElement=t}}
|
23
|
+
customElements.define("cart-notification",CartNotification);
|
24
|
+
```
|
25
|
+
[https://cdn.shopify.com/s/files/1/0551/7626/5784/t/31/assets/cart-notification.js?v=1877081553624793631](https://cdn.shopify.com/s/files/1/0551/7626/5784/t/31/assets/cart-notification.js?v=1877081553624793631)
|
1
参考URLを追記
answer
CHANGED
@@ -2,4 +2,7 @@
|
|
2
2
|
|
3
3
|
もし、`document.querySelector('cart-notification')`で正しいのであれば、`product-form`と同様に独自タグをどこかで定義しており、その中で`setActiveElement` メソッドを定義しているはずです。
|
4
4
|
|
5
|
-
定義が漏れている、依存関係が崩れている、などのことが起きていると思いますので、その部分を確認してみてください。
|
5
|
+
定義が漏れている、依存関係が崩れている、などのことが起きていると思いますので、その部分を確認してみてください。
|
6
|
+
|
7
|
+
参考:
|
8
|
+
[Custom elements](https://ja.javascript.info/custom-elements)
|