Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

页面继承基类,子类编译后的 wxml 文件会自动 import 基类的 wxml文件 #3914

Closed
Luckymin opened this issue Jul 22, 2019 · 3 comments
Assignees

Comments

@Luckymin
Copy link

问题描述

页面继承基类,子类编译后的 wxml 文件会自动 import 基类的 wxml文件,不影响程序运行但是开发者工具会报警告

复现步骤

base.ts

import Taro from '@tarojs/taro'

export default class Base<Props, State> extends Taro.Component<Props, State> {
  onReachBottom () {
    Taro.eventCenter.trigger('onScrollToLower')
  }
}

home.tsx

import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import Base from './base'
import './index.scss'

type State = {}
type Props = {}
export default class Home extends Base<Props, State> {
  render () {
    return (
      <View className='home'>
        { this.renderTest() }
      </View>
    )
  }

  renderTest () {
    return (
      <View>test</View>
    )
  }
}

编译后的 home.wxml 文件

<import src="./base.wxml" />
<block wx:if="{{$taroCompReady}}">
    <view class="home">
        <template is="renderTest" data="{{...anonymousState__temp}}"></template>
    </view>
</block>
<template name="renderTest">
    <block>
        <view>test</view>
    </block>
</template>

期望行为

编译后不引用不存在的 base.wxml 文件

<import src="./base.wxml" />

报错信息

WXMLRT_$gwx:./pages/home/home.wxml:import:1:1: Path `./base.wxml` not found from `./pages/home/home.wxml`.

./pages/home/home.wxml
 Path `./base.wxml` not found from `./pages/home/home.wxml`.
> 1 | <import src="./base.wxml" />
    | ^
  2 | <block wx:if="{{$taroCompReady}}">
  3 |     <view class="home">
  4 |         <template is="renderTest" data="{{...anonymousState__temp}}"></template>

系统信息

  • 操作系统: [e.g. macOS High Sierra 10.13.6]
  • Taro 版本 [e.g. Taro v1.3.4]
  • Node.js 版本 [e.g. v11.10.0]
  • 报错平台 [weapp]

补充信息

home.tsx 中的 render 如果不调用 renderTest() 那么编译后的 home.wxml 就不会引用 base.wxml 文件了

home.tsx

import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import Base from './base'
import './index.scss'

type State = {}
type Props = {}
export default class Home extends Base<Props, State> {
  render () {
    return (
      <View className='home'>
        <View>test</View>
      </View>
    )
  }
}

编译后的 home.wxml

<block wx:if="{{$taroCompReady}}">
    <view class="home">
        <view>test</view>
    </view>
</block>
@taro-bot
Copy link

taro-bot bot commented Jul 22, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Jul 22, 2019

CC @yuche

@taro-bot taro-bot bot assigned yuche Jul 22, 2019
@yuche
Copy link
Contributor

yuche commented Jul 22, 2019

你把组件 Homerender() 放在最后面就不会有这个报错了,因为编译器解析是自上而下的,解析到 render 方法的时候并不知道它的自己有 renderTest 方法,所以就打算从父类去寻找。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants