我对组件开发很陌生,并且正在努力打印一个简单的 hello world。有人能帮我吗?
重现步骤:
1. now-cli login --host stack.service-now.com
2. now-cli project --name nowjedi-hello -- description 'A web component printing Hello World'
3. npm install
4. now-cli develop --open
退货:
SyntaxError: Failed to execute 'define' on 'CustomElementRegistry': "299742-nowjedi-hello" is not a valid custom element name
我正在关注“开发你的组件”。知道发生了什么事吗? https://developer.servicenow.com/dev.do#!/guide/orlando/now-experience/cli/development-flow/.
名字不能以数字开头
来源:https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
简短摘要:
start 带有 ASCII 小写字母,因此 HTML 解析器会将它们视为标签而不是文本。
不要包含任何 ASCII 大写字母。
<math-α> or <emotion-😍>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello!</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<my-test-element-one>
</my-test-element-one>
<script>
class my_test_element_one extends HTMLElement{
connectedCallback(){
this.innerHTML=` <div class="myclass" style=" width:600px;height:500px; background-color:green">
<img src="https://images.pexels.com/photos/267415/pexels-photo-267415.jpeg?auto=compress&cs=tinysrgb&w=300" />
</div>`
}
}
customElements.define('my-test-element-one', my_test_element_one);
</script>
</body>
</html>