gohomeschool
gohomeschool
  • 发布:2022-04-22 14:24
  • 更新:2022-04-22 15:06
  • 阅读:225

点击popup组件的弹窗的同意后,如何向数据表s中增加数据字段name,amount这两个记录?

分类:uni-app
2022-04-22 14:24 负责人:无 分享
已邀请:
gohomeschool

gohomeschool (作者)

< template>
<view>
<button @click="open">提交</button>
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog mode="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm">
<view>
<input v-model="name" />
</view>
<view>
<input v-model="amount" />
</view>
</uni-popup-dialog>
</uni-popup>
</view>
< /template>

gohomeschool

gohomeschool (作者)

"script"
export default {
data() {
return {
name: '',
amount: ''
}
},
methods: {
open() {
this.$refs.popup.open()
},
/**

  • 点击取消按钮触发
  • @param {Object} done
    */
    close() {
    // TODO 做一些其他的事情,before-close 为true的情况下,手动执行 close 才会关闭对话框
    // ...
    this.$refs.popup.close()
    },
    /**
  • 点击确认按钮触发
  • @param {Object} done
  • @param {Object} value
    */
    confirm(value) {
    // 输入框的值
    console.log(value)
    // TODO 做一些其他的事情,手动执行 close 才会关闭对话框
    // ...

    if (!this.name || !this.amount) {  
      return  
    }  
    
    const collection = "" // 数据库表名  
    this.addDataToDatabase(collection, this.name, this.amount)  
    
    this.$refs.popup.close()  

    },

    async addDataToDatabase(collection, name, amount) {
    uni.showLoading({
    title: '处理中...'
    })
    return await uniCloud.callFunction({
    name: collection,
    data: {
    name: name,
    amount: amount
    }
    }).then((res) => {
    uni.hideLoading()
    return res.result.id
    }).catch((err) => {
    uni.hideLoading()
    uni.showModal({
    content: 添加数据失败,错误信息为:${err.message},
    showCancel: false
    })
    console.error(err)
    })
    }
    }
    }
    "/script"
    '''

gohomeschool

gohomeschool (作者)

"script"需替换成<script>
"/script"需替换</script>

gohomeschool

gohomeschool (作者)


<view>  
<button @click="open">提交</button>  
<uni-popup ref="popup" type="dialog">  
<uni-popup-dialog mode="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm">  
<view>  
<input v-model="name" />  
</view>  
<view>  
<input v-model="amount" />  
</view>  
</uni-popup-dialog>  
</uni-popup>  
</view>  
< /template> ```
gohomeschool

gohomeschool (作者)


<script>  
  export default {  
    data() {  
    return {  
        name: '',  
        amount: ''  
      }  
    },  
    methods: {  
      open() {  
        this.$refs.popup.open()  
      },  
      /**  
       * 点击取消按钮触发  
       * @param {Object} done  
       */  
      close() {  
        // TODO 做一些其他的事情,before-close 为true的情况下,手动执行 close 才会关闭对话框  
        // ...  
        this.$refs.popup.close()  
      },  
      /**  
       * 点击确认按钮触发  
       * @param {Object} done  
       * @param {Object} value  
       */  
      confirm(value) {  
        // 输入框的值  
        console.log(value)  
        // TODO 做一些其他的事情,手动执行 close 才会关闭对话框  
        // ...  

        if (!this.name || !this.amount) {  
          return  
        }  

        const collection = "" // 数据库表名  
        this.addDataToDatabase(collection, this.name, this.amount)  

        this.$refs.popup.close()  
      },  

      async addDataToDatabase(collection, name, amount) {  
        uni.showLoading({  
          title: '处理中...'  
        })  
        return await uniCloud.callFunction({  
          name: collection,  
          data: {  
            name: name,  
            amount: amount  
          }  
        }).then((res) => {  
          uni.hideLoading()  
          return res.result.id  
        }).catch((err) => {  
          uni.hideLoading()  
          uni.showModal({  
            content: `添加数据失败,错误信息为:${err.message}`,  
            showCancel: false  
          })  
          console.error(err)  
        })  
      }  
    }  
  }  
</script>  

该问题目前已经被锁定, 无法添加新回复