html 标签 < 与 tag name 之间不能有空格
下面模板字符串中的 input 标签,<input >
,<input />
,<input ><input />
都能正常显示,< input>
则不行。即左尖括号与标签名之间不能有空格。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel="stylesheet" type="text/css" media="screen" href="main.css"> -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<custom-input v-model=searchText></custom-input>
<div>{{searchText}}</div>
</div>
<script>
Vue.component('custom-input', {
props: ['value'],
template: `
<input
v-bind:value="value"
v-on:input="$emit('input', $event.target.value)"
>
`
});
new Vue({
el: '#app',
data: {
searchText: "11"
}
})
</script>
</body>
</html>