Vue的过滤器和渲染函数

今天我学习了Vue的过滤器和渲染函数。Vue的过滤器可以对数据进行格式化和处理,例如把日期格式化为特定的格式:

Vue.filter('dateFormat', function(value, format) {

  return moment(value).format(format)

})

 

<span>{{ date | dateFormat('YYYY-MM-DD') }}</span>

 

Vue的渲染函数可以让我们直接生成虚拟DOM,这对于动态生成和渲染大量元素的场景非常有用:

Vue.component('my-component', {

  render: function(createElement) {

    return createElement('div', ['Hello ', this.name, '!'])

  },

  props: ['name']

})

 

然后在html中使用自定义标签调用该组件:

<my-component name="Vue"></my-component>

 

明天我将继续学习VuemixinVue服务器端渲染。

posted @ 2023-05-30 20:15  ITJAMESKING  阅读(23)  评论(0编辑  收藏  举报