dtcloud owl新增的qweb模板t指令解析

在这里插入图片描述

1、t-ref+js的useRef
作用是qweb中定义的组件可被js文件引用,代码如下:

<script charset='UTF-8' src='../owl.js' > </script>
<script>
    const {Component} = owl;
    const {Xml} =owl.tags;
    const {mount} =owl;
    const {useRef} = owl.hooks; 
    class App extends Component{
       static template = xml~
       <div>
           <h1>Hello owl!</h1>
           <button type="button" t-on-click="onClick">
              Click me!
           </button>
          <div t-ref="divContent">
               i am div!
          </div>
          <div>
          onClick(){
              console.log(useRef('divContent'));            
            }
           ~
           }

</script>

此处要注意template里面只能一个div根节点,不允许出现两个并排的div
结果:
在这里插入图片描述
t-on-* *代表所有html事件,如click,dbclick,ordrag,change等,参见网址:
https://www.runoob.com/tags/ref-eventattributes.html
2、t-key
qweb循环节点的唯一标识,t-foreach循环时必须指定t-key
3、t-model
可用于input等的输入绑定
4、t-props
设定参数及传值,例如:

static compotents = {child};
items=[1,2,3,4,5,6]
class child extends Component{
    static template = xml~
    <div>
        I am a child[<t t-esc="props.index"/>]
   </div>
   static props = {'index':{}   }
   static defaultprops = {'index':0  }
~
}
<child t-foreach='items' t-as='index' index='index' t-key='index'></child>

输出结果:
在这里插入图片描述
5、t-componets

owl要挂载的组件,是owl的基本组成部分,例如:
class child extends Component{
    static template = xml~
    <div>
        I am a child[<t t-esc="props.index"/>]
   </div>
   static props = {'index':{}   }
   static defaultprops = {'index':0  }
~
}

挂载:
let app=new App();
app.mount(document.body);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值