Javascript Vue-部分模板
我在.vue组件文件中找到了一个模板。假设我需要重用此模板的一部分(Javascript Vue-部分模板,javascript,templates,vue.js,Javascript,Templates,Vue.js,我在.vue组件文件中找到了一个模板。假设我需要重用此模板的一部分(),如果需要重复创建同一个代码段,最好的方法是使用。下面是一个简单的示例: Vue.component('my-img', { functional: true, render: function (createElement, context) { return createElement('img', { attrs: { src: context.props.src } }) }, props: {
),如果需要重复创建同一个代码段,最好的方法是使用。下面是一个简单的示例:
Vue.component('my-img', {
functional: true,
render: function (createElement, context) {
return createElement('img', { attrs: { src: context.props.src } })
},
props: {
src: 'http://example.com/img.png'
}
})
技术上是一样的(v-else
对于后者),最好的方法是将其隔离到一个新组件中
Vue.component('my-img', {
functional: true,
render: function (createElement, context) {
return createElement('img', { attrs: { src: context.props.src } })
},
props: {
src: 'http://example.com/img.png'
}
})