我试图在一个模态中循环和引用vue数据值,并且我得到一个错误,该字段需要被激活,尽管在组件初始化中提供了值。知道为什么会这样吗?
小提琴: https://jsfiddle.net/mwLbw11k/2618/
JS
// register modal component
Vue.component('modal', {
template: '#modal-template'
})
// start app
new Vue({
el: '#app',
data: {
myData: [{'first': 'Matt', 'last': 'Smith'}, {'first': 'Tom', 'last': 'Brady'}],
showModal: false
}
})
HTML
<script type="text/x-template" id="modal-template">
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
default header
</slot>
</div>
<div class="modal-body">
<slot name="body">
<ul>
<li v-for="user in myData"> {{ user.first }} {{ user.last }}</li>
</ul>
</slot>
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" @click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</script>
<!-- app -->
<div id="app">
<button id="show-modal" @click="showModal = true">Show Modal</button>
<!-- use the modal component, pass in the prop -->
<modal v-if="showModal" @close="showModal = false">
</modal>
</div>
Vue警告
[Vue warn]: Property or method "myData" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
答案 0 :(得分:1)
Yous应该将myData
添加到modal
组件道具
Vue.component('modal', {
template: '#modal-template',
props: ['myData']
})
然后从父母传递它:
<modal v-if="showModal" :my-data="myData" @close="showModal = false">
</modal>
答案 1 :(得分:1)
更正了Bsalex的demo
import numpy as np
from scipy.integrate import simps
y = np.array([1,2,3,4,5])
y1= np.array([5,5,5,5,5])
print np.trapz(y,dx=1)
print simps(y,dx=1)
print np.trapz(y1,dx=1)
print simps(y1,dx=1)