MENU

vue

h5与uniapp之间通过webview通信

引入

<!-- 引入 uniapp webview sdk 在body后 -->
<script src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>

网页向 APP 传值

function postMsg() {
    uni.getEnv(function (res) {
      console.log('shebei' + JSON.stringify(res))
    })
    // 向 APP 发送消息 (注意看这里 01)
    uni.postMessage({
      data: {
        name: 'head',
        age: 19,
        appfv:true
      }
    })

APP 接受传值

<template>
    <view class="content"><web-view src="http://" @message="handleMessage"></web-view></view>
</template>

<script setup>


function handleMessage(evt) {
    const [data] = evt.detail.data
}


</script>

APP 向网页传值

就是链接里加了个参数

Read More

Vue组件相关笔记

使用组件三大步骤

定义组件(创建组件)

使用 Vue.extend(options)创建,options 中无 el,因为最终所有的组件都要经过一个 vm 的管理,由 vm 中的 el 决定服务于哪个容器,此外 data 必须写成函数,以避免组件被复用时,数据存在引用关系

Read More

Vue自定义指令总结

语法

  1. 局部指令
new Vue({
    directives:{指令名:配置对象}
})
//or
new Vue({
    directives:{指令名:回调函数}
})
  1. 全局指令
Vue.directives(指令名,配置对象)
//or
Vue.directives(指令名,回调函数)

配置对象中常用的三个回调

  1. bind:指令与元素成功绑定时调用
  2. inserted:指令所在元素被插入页面时调用
  3. update:指令所在模板结构被重新解析时调用

这三个回调函数中的 this 都指向 windows,简写形式只能定义 bind 和 update 两个回调

Read More