我是 vue.js 框架的新手。我正在研究它并尝试将其用于我的爱好项目。我尝试用 props 创建这个组件(组件尚未完成):
Vue.component('ingredient_select', {
props: [name, selectedValue, text, ajaxUrl],
template: `
<select name="{{ name }}">
<option value="{{ selectedValue }}">{{ text }}</option>
</select>
`
});
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js"></script>
</head>
<body></body>
</html>
Vue.js 抛出错误:“ReferenceError:selectedValue 未定义”。
我从我的 vue 模板中删除了组件的标签
P.S.:我的 IDE (PHP Storm) 没有显示任何 JavaScript 语法错误。
最佳答案
您应该将 props 定义为字符串数组,而不是变量:
props: ['selectedValue', 'text', 'ajaxUrl']
此外,'name'
对于 Prop 来说并不是一个很好的名称。
Vue.component('ingredient_select', {
props: ['sname', 'selectedValue', 'text', 'ajaxUrl'],
template: `
<select name="{{ sname }}">
<option value="{{ selectedValue }}">{{ text }}</option>
</select>
`
});
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js"></script>
</head>
<body></body>
</html>
关于javascript - Vue 组件的 prop 未定义( fatal error ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54380875/