javascript - 我的代码什么也没做。可能是什么原因?
问题描述
Vue组件不渲染也没有错误,但是它加载了vue cdn。没有什么可以代替组件。
<!DOCTYPE html>
<head>
<title>Vue</title>
</head>
<body>
<blog-post :title="My journey with Vue"></blog-post>
<blog-post v-bind:title="Blogging with Vue"></blog-post>
<blog-post title="Why Vue is so fun"></blog-post>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/v`enter code here`ue.js"></script>
<script>
Vue.component('blog-post', {
props: ['title'],
template: '<div><h3>{{ title }}</h3></div>'
})
</script>
</body>
</html>
解决方案
- 您应该创建一个 Vue 实例并将其绑定到一个元素
- 如果字符串按字面意思传递给
title
道具,:
请在绑定之前删除。这样,Vue 不会尝试将它们作为表达式求值
<!DOCTYPE html>
<head>
<title>Vue</title>
</head>
<body>
<div id="app">
<blog-post title="My journey with Vue"></blog-post>
<blog-post title="Blogging with Vue"></blog-post>
<blog-post title="Why Vue is so fun"></blog-post>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script>
Vue.component('blog-post', {
props: ['title'],
template: '<div><h3>{{ title }}</h3></div>'
});
new Vue({
el: '#app'
});
</script>
</body>
</html>
推荐阅读
- python - 如何以有效的方式在python中的sql上与外部连接器进行内部连接
- arrays - 无法在索引集合 laravel 中创建新的数组 foreach 记录
- reactjs - StopPropogation 基于反应中的条件
- c# - 当我们将非可空属性复制到可空属性时获取空值
- javascript - 使用 Cognito 用户池组调用没有联合身份的 Lambda 函数
- sql - 3 个表不支持加入表达式
- performance - 并行处理加速 S(n)
- wordpress - 自定义帖子类型的自定义 URL
- android - 当您已经在活动3时如何顺序执行活动1、2、3
- ruby - '除非'值可以增加吗?