javascript - 如何给vue异步组件绑定事件

 蓶逺訫動_129 发布于 2022-11-27 12:58

vue中有异步组件功能https://vuejs.org.cn/guide/components.html#异步组件
但是异步组件里面怎么绑定事件呢?换句话说,怎么才能像正常组件那样双向绑定数据?

Vue.component('async-example', function (resolve, reject) {
  setTimeout(function () {
    resolve({
      template: '

I am async!

' }) }, 1000) })

其中的click,model都是无效的,该怎么操作才能使用呢?

1 个回答
  • 为什么不行呢?

    补充:

    增加绑定数据部分

    Vue.component('async-example', function (resolve, reject) {
      setTimeout(function () {
        resolve({
          template: '<p @click="show">I am async!</p><input type="text" v-model="val"/>',
          data: function(){
              return {
                  val: 'Fucking it'
              };
          },
          methods: {
              show: function(){
                  alert('show show!');
              }
          }
        })
      }, 1000)
    })

    这样不行么?

    2022-11-27 13:58 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有