vue.js - 如何在不通过 div 的情况下正确访问 vue.js 中的 props
问题描述
我在我的 vue 根目录的 create 钩子中执行了一个 api 调用。然后我有一个组件试图使用从 api 调用返回的数据。
我的问题很简单。下面的示例有效,但有没有办法<stage-execs></stage-execs>
不传入 job_execs = job_execs ?
我更喜欢使用更简洁的外观<stage-execs></stage-execs>
<div id="vue-job">
<div class="column">
<div class="row">
<stage-execs v-bind:job_execs=job_execs></stage-execs>
<br><br>
</div>
</div>
<script>
Vue.component('stage-execs', {
delimiters: [ '[[', ']]' ],
props: ['job_execs'],
template: `
<ul id="example-1">
<h3>Stages</h3>
<li v-for="item in this.job_execs">
[[ item.build_id ]]
</li>
</ul>
`,
var v_root = new Vue({
delimiters: [ '[[', ']]' ],
el: '#vue-job',
data: {
job_execs: []
},
created() {
url="http://{{ api_endpoint }}"
fetch(url)
.then(response => response.json())
.then(body => {
for(i=0; i<body.length; i++){
this.job_execs.push({
'build_id': JSON.stringify(body[i].build_id),
'status': JSON.stringify(body[i].status.name),
})
}
})
.catch( err => {
console.log('Error Fetching:', url, err);
return { 'failure': url, 'reason': err };
});
},
});
解决方案
不,你不能。你能做的最好的就是失去v-bind
,所以:job_execs=job_execs
。(the:
是 v-bind 的简写)
推荐阅读
- c# - 使用 C# 时如何获取传入数据包的 TTL
- linux - 在 Linux 中为 SMuFL 预览和键入 Unicode 字体(专用区域/基本多语言平面)
- r - 无法运行双向重复测量方差分析;0(非NA)案例
- java - 每次新构建后 Xpaths div 都会发生变化
- python - 在 tkinter 中禁用 Windows 操作系统缩放?
- mysql - MySQL DB 结构 - 调度系统
- git - 停止跟踪对文件的更改
- c# - C# 问题诊断 InvalidOperationException
- angular - 如何在 Angular 应用程序中为 PDFMake 导入自定义字体?
- python - Python pyodbc 和 Oracle SQL 无效数字错误