1.①绑定<a :href=‘url‘>点</a><button @click=‘say‘>点</button>②双向数据绑定MVVM用v-model③Object.defineProperty()

目录

调试工具:

插件安装目录:

一:基本语法

1.引入 vue.js

2.body里面必须有一个挂载点app

3.script里面有一个 vm实例化对象,和挂载点进行挂载

二:数据的绑定及事件的添加(跳转和点击事件)及简写

1.    点我去百度

2.    点击事件绑定

三:双向数据绑定MVVM和data的两种写法

1.双向数据绑定:一般情况下只针对表单类元素使用 v-model

2.data可以是对象也可以是函数

四:Object.defineProperty()专门用来监控对象属性变化的,

添加或修改对象的属性为响应式属性,实现双向绑定

有三个参数

1.第一个参数:目标对象

2.第二个参数:需要定义的属性或方法的名字。

3.第三个参数:目标属性所拥有的特性。(descriptor)

Object.keys方法之详解



调试工具:

插件安装目录:

一:基本语法

1.引入 vue.js

2.body里面必须有一个挂载点app

3.script里面有一个 vm实例化对象,和挂载点进行挂载

请求回来的数据,是配置对象里的data

二:数据的绑定及事件的添加(跳转和点击事件)及简写

1.    <a v-bind:href='url'>点我去百度</a>

2.    <button v-on:click='say'>点击事件绑定</button>

三:双向数据绑定MVVM和data的两种写法

1.双向数据绑定:一般情况下只针对表单类元素使用 v-model

<div id="app">
        <p>{{msg}}</p>
        <input type="text" v-model='msg'></input>  
        <!-- 当input里面的值改变时,p标签里面的字也改变 -->
    </div>

    <script>
        const vm = new Vue({
            el: '#app',
            // data 可以是对象也可以是函数
            /*             data: {
                        }, */
            data() {
                return {
                    msg: '哈喽~'
                }
            },
        })
    </script>

2.data可以是对象也可以是函数

四:Object.defineProperty()专门用来监控对象属性变化的,

添加或修改对象的属性为响应式属性,实现双向绑定

        let s = {
            one: '1',
            two: '2'
        }
        Object.defineProperty(s, 'three', {
            value: 3
        })
        console.log(s)

有三个参数

1.第一个参数:目标对象

2.第二个参数:需要定义的属性或方法的名字。

3.第三个参数:目标属性所拥有的特性。(descriptor)

第三个参数descriptor里面有以下取值:第一次设置时以下(除了value)的值默认为false

①value:属性的值

②writable:如果为false,属性的值就不能被重写,只能为只读了,再次赋值不起作用

③configurable:总开关,一旦为false,就不能再设置他的(value,writable,configurable),再次赋值报错

④enumerable:是否能在for…in循环中遍历出来或在Object.keys中列举出来。

⑤set:

⑥get:

Object.keys方法之详解

 let s = {
            one: '1',
            two: '2'
        }
        Object.defineProperty(s, 'three', {
            value: 3,
            enumerable: true
        })
        console.log(Object.keys(s))//为true时可以遍历出新添加的属性名three['one', 'two', 'three']

set和get

<script>
        let s = {
            one: '1',
            two: '2'
        }
        let s2 = {}
        Object.defineProperty(s, 'three', {
            get() {
                // 当访问对象的three属性时
                return this.one + "-" + this.two
            },
            set(val) {
                // 当对象的three属性被修改时,
                const arr = val.split('-')   //split是以-为分隔符分隔val字符串到arr数组中去
                this.one = arr[0]
                this.two = arr[1]
            }
        })
        console.log(s.three)  //1-2
        s.three = '4-5'
        console.log(s.one)    //4
        console.log(s.two)    //5
    </script>

模拟数据代理:

        // 模拟数据代理
        let vm = {}
        let data = { msg: "hello" }

        Object.defineProperty(vm, 'msg', {
            get() {
                return data.msg
            },
            set(val) {
                // 当vm的值修改时
                data.msg = val
            }
        })

        console.log(vm.msg)   //hello

        vm.msg = '我更改了'
        console.log(vm.msg)   //hello
        console.log(data.msg) //hello

.

<template> <view class="content"> <!-- <image class="logo" src="/static/logo.png"></image> --> <view class="text-area"> <text class="title">{{title}}</text> </view> <view class="text-area"> <text class="title">{{title}}</text> </view> <view class="text-area"> <button @click="handleclick">呼叫服务器</button> </view> <unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" collection="contacts"> <view v-if="error">{{error.message}}</view> <view v-else> <uni-list> <uni-list-item v-for="item in data" @longpress.native="rmItem(item._id)" :key="item._id" :title="item.name" :note="item.phone" link></uni-list-item> </uni-list> </view> </unicloud-db> </view> </template> <script setup> import { reactive,ref } from 'vue'; const title = ref("hello-mycloud") const handleclick = async() => { const myfunction = uniCloud.importObject("myfunction") const res = await myfunction.say("你好,我是前端") uni.showModal({ content:JSON.stringify((res) ) }) } const rmItem = (id)=>{ // app.$refs.udb.remove(id) //this.$refs.udb.remove(id) } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .logo { height: 200rpx; width: 200rpx; margin-top: 200rpx; margin-left: auto; margin-right: auto; margin-bottom: 50rpx; } .text-area { display: flex; justify-content: center; } .title { font-size: 36rpx; color: #8f8f94; } </style> 这段代码中rmItem的功能是删除云数据的当前项,需要用vue3组合式风格,怎么接着往下写
03-10
<template> <view class="content"> <!-- <image class="logo" src="/static/logo.png"></image> --> <!-- view class="text-area"> <text class="title">{{title}}</text> </view> <view class="text-area"> <text class="title">{{title}}</text> </view> <view class="text-area"> <button @click="handleclick">呼叫服务器</button> </view> --> <unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" collection="datalist"> <view v-if="error">{{error.message}}</view> <view v-else> <uni-list> <uni-list-item v-for="item in data" :key="item._id" :title="item.name" :note="item.phone" @click="rmItem(item._id)" link></uni-list-item> </uni-list> </view> </unicloud-db> </view> </template> <script setup> // import { ref } from 'vue' // const udb = ref("") const rmItem = ()=>{ rmItem(id){ this.$refs.udb.remove(id) } } // export default { // data(){ // return{ // } // }, // methods:{ // rmItem(id){ // this.$refs.udb.remove(id) // } // } // } // import { // reactive, // ref // } from 'vue'; // const title = ref("hello-mycloud") // const handleclick = async () => { // const myfunction = uniCloud.importObject("myfunction") // const res = await myfunction.say("你好,我是前端") // uni.showModal({ // content: JSON.stringify((res) // ) // }) // } </script> <style> /* .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .logo { height: 200rpx; width: 200rpx; margin-top: 200rpx; margin-left: auto; margin-right: auto; margin-bottom: 50rpx; } .text-area { display: flex; justify-content: center; } .title { font-size: 36rpx; color: #8f8f94; } */ </style>这段代码是vue3组合式风格,需要实现击当前项进行删除操作,但是击后没响应,为什么
03-11
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值