Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Vue-部分模板_Javascript_Templates_Vue.js - Fatal编程技术网

Javascript 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组件文件中找到了一个模板。假设我需要重用此模板的一部分(
),如果需要重复创建同一个代码段,最好的方法是使用。下面是一个简单的示例:

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'
  }
})