babel-plugin-transform-vue-jsx icon indicating copy to clipboard operation
babel-plugin-transform-vue-jsx copied to clipboard

When a functional component is inserted outside of the document(#app), the context is not available within the component.

Open fantasy525 opened this issue 7 years ago • 2 comments

//src/index.vue
 export default {
      functional:true,
      props:{
          styObj:{
            type:Object,
            default(){
              return {
                width:'300px',
                height:'300px'
              }
            }
          },
          title:{
            type:String,
            default:'00'
          }
        },
      render(h,context){
        return(
          <div class="dialog" >
            {context.props.title}
          </div>
        )
      }
    }

and import compoent

  import com from './src'
  const Dia=Vue.extend(com)
 const vm=new Dia()
 vm.$mount()
 document.body.appendChild(vm.$el)

but it cant't work errors: context.props.title is undefined

fantasy525 avatar May 18 '18 08:05 fantasy525

Yes, I found the same problem, too. But it can be used as long as it is ‘import’ inside the component. 要重新局部引入才能用,因为不复杂,果断用render普通语法了。

evansun1995 avatar Jun 28 '18 14:06 evansun1995

This still exists in version 2.5.17. Same use case as OP.

xxRockOnxx avatar Nov 25 '18 15:11 xxRockOnxx