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

TypeError: this.$watch is not a function #3

Closed
nyrf opened this issue Nov 11, 2018 · 4 comments
Closed

TypeError: this.$watch is not a function #3

nyrf opened this issue Nov 11, 2018 · 4 comments

Comments

@nyrf
Copy link

nyrf commented Nov 11, 2018

按文档这写的,https://ecomfe.github.io/okam/#/component/setData?id=%E7%9B%91%E5%90%AC%E5%99%A8

@wuhy
Copy link
Collaborator

wuhy commented Nov 11, 2018

关于这个问题,可能文档上没写清楚,由于 okam 框架是渐进式增强,因此如果需要使用 watch 能力,需要在构建配置 framework 增加配置项:['data', 'watch'],所以请先确认下是否有加上相关配置。

@nyrf
Copy link
Author

nyrf commented Nov 11, 2018

这个加上了,不报错,不过从父组件传过来的props更新后,watch没有任何变化 ,

   framework: [
        'data',
        'ref',
        'watch'
    ],

index.vue

<template>
    <view>
        <div @click='update'>Click check</div>
    </view>
</template>
<script>
import Hello from '../../components/Hello';
export default {
    config: {
        title: 'Page Title'
    },

    components: {
        Hello
    },
     data: {
       title: 'title'
    },

   methods: {
    update () {
            this.title = 'title updated'
       },
   }
   
}
</script>
<template>
    <view class="hello-wrap">
        {{title}}
    </view>
</template>
<script>
export default {
    config: {
    },

    props: {
        title: String
    },

   created() {
     this.$watch('title', function (newVal, oldVal) {
          console.log('watch', newVal, oldVal, 'donw')
      });
   },

    data: {
    },

    methods: {

    }
};
</script>

点击页面上的update,子组件title看着是更新了,但watch这里newVal和oldVal都是空

@wuhy
Copy link
Collaborator

wuhy commented Nov 12, 2018

还有明确下是微信下还是?我这边在百度小程序、微信小程序都没有问题,支付宝小程序由于不支持 props observer 所以目前有点问题

@nyrf
Copy link
Author

nyrf commented Nov 12, 2018

我用的微信,昨晚一直不可以,今天可以了

@nyrf nyrf closed this as completed Nov 12, 2018
liujiaor added a commit that referenced this issue Oct 27, 2020
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