Weex开发中的应用小笔记

内容:

获取输入或其他操作使得值一直改变并在一段不改变的时间后执行下一步操作(输入搜索关键字并执行搜索)

https://vuejs.org/v2/guide/computed.html?spm=a2c7j.-zh-docs-components-recycle-list.0.0.9f1a3dcb7cO5F4#Watchers

var watchExampleVM = new Vue({
  el: '#watch-example',
  data: {
    question: '',
    answer: 'I cannot give you an answer until you ask a question!'
  },
  watch: {
    // whenever question changes, this function will run
    question: function (newQuestion, oldQuestion) {
      this.answer = 'Waiting for you to stop typing...'
      this.debouncedGetAnswer()
    }
  },
  created: function () {
    // _.debounce is a function provided by lodash to limit how
    // often a particularly expensive operation can be run.
    // In this case, we want to limit how often we access
    // yesno.wtf/api, waiting until the user has completely
    // finished typing before making the ajax request. To learn
    // more about the _.debounce function (and its cousin
    // _.throttle), visit: https://lodash.com/docs#debounce
    this.debouncedGetAnswer = _.debounce(this.getAnswer, 500)
  },
  methods: {
    getAnswer: function () {
      if (this.question.indexOf('?') === -1) {
        this.answer = 'Questions usually contain a question mark. ;-)'
        return
      }
      this.answer = 'Thinking...'
      var vm = this
      axios.get('https://yesno.wtf/api')
        .then(function (response) {
          vm.answer = _.capitalize(response.data.answer)
        })
        .catch(function (error) {
          vm.answer = 'Error! Could not reach the API. ' + error
        })
    }
  }
})
</script>

 

js获取当前页面的地址(此处为完整路径)

this.$getConfig().bundleUrl

 

复杂表达式不应该出现在数据绑定中,可以通过定义计算computed属性来实现方便管理维护

<div id="example">
  <p>Original message: "{{ message }}"</p>
  <p>Computed reversed message: "{{ reversedMessage }}"</p>
</div>
var vm = new Vue({
  el: '#example',
  data: {
    message: 'Hello'
  },
  computed: {
    // a computed getter
    reversedMessage: function () {
      // `this` points to the vm instance
      return this.message.split('').reverse().join('')
    }
  }
})

 

值绑定的操作只发生一次

通过使用 v-once 指令,你也能执行一次性地插值,当数据改变时,插值处的内容不会更新。但请留心这会影响到该节点上所有的数据绑定:

<span v-once>This will never change: {{ msg }}</span>

 

将输入控件的值通过v-model和属性值进行绑定

http://doc.vue-js.com/v2/guide/

<div id="app">
  <p>{{ message }}</p>
  <input v-model="message">
</div>

 

在莫个VUE文件中引用自定义控件的方法

import { WxcTabPage, WxcPanItem, Utils, BindEnv,WxcPopup } from 'weex-ui';
  import ProblemsItem from "./problems-item";

通过比较可以容易发现前后写法之间的关系(没有设置component属性值)alt+点击可以进入查看莫个实现的写法

自定义控件增加一个事件(带上参数)

this.$emit('sendRequestForQuestion', this.problem);

设置属性时处理这个事件

<problems-item @sendRequestForQuestion = sendRequestForQuestion :problem=p />

上面同时设定了属性problem这个在空间中的属性定义为

export default {
    components: { WxcPanItem },
    props: {
      problem: {
        type: Object,
        default: {}
      },
    },
    data: () => ({

    }),
    methods: {
      handleAskQuestion() {
        // this.$notice.toast('handleAskQuestion:')
        this.$emit('sendRequestForQuestion', this.problem);
      }
    }
  }

data属性一定要写对位置,否者比如遇到BOOL类型的属性,可能出现页面不刷新或者只刷新第一次的问题

wxc-popup显示和点击空白会出现动画效果,点击上面的控件隐藏需要通过hide方法

popupBottomHide () {
        this.$refs.popupContent.hide()
        // this.$notice.toast('popupOverlayBottomClick:')
      },

 

flex-grow元素占据父元素剩余空间的比例

list不存在自定义重用标识,每次都是重新移除/添加控件到Cell上面,而且不支持Group类型的list

http://dotwe.org/vue/035a0ee995d71c510161cba6e123d818

选项卡左右滑动切换类型页面

https://alibaba.github.io/weex-ui/#/cn/packages/wxc-tab-page/

左右上下弹出控件

https://alibaba.github.io/weex-ui/#/cn/packages/wxc-popup/  

weex动画使用animation.transition函数

http://dotwe.org/vue/3e8660d7182f24901f122a0855c09370

https://www.jianshu.com/p/ab3e9f06f106

<script>
    const animation = weex.requireModule('animation')
    const modal = weex.requireModule('modal')

    export default {
        data: function () {
            return {
                current_rotate: 0
            }
        },
        mounted () {
            let that = this
            let el = this.$refs.test
            setInterval(function () {
                that.rotate(el)
            }, 600)
        },
        methods: {
            rotate (el) {
                let self = this;
                this.current_rotate+=360;
                animation.transition(el, {
                    styles: {
                        color: '#FF0000',
                        transform: 'rotate(' + self.current_rotate + 'deg)',
                        transformOrigin: 'center center'
                    },
                    duration: 600, //ms
                    timingFunction: 'ease',
                    delay: 0 //ms
                },function () {

                })
            }
        }
    }
</script>

 

转载于:https://www.cnblogs.com/yuxiaoyiyou/p/10592948.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值