实例:

methods:{
     onCreate:async function()  {
      const router = useRouter()
      const route = useRoute()
      const { id = '', f = 1 } = route.query
      console.log("======="+id)
      const res = await reqGetOrderNumByClientId({
        clientId: id
      })
         console.log("-------------------"+res+res.msg)
      if (res.code === 200) {
         await router.push({
          path: '/app/create',
          query: {
            id: id,
            f: f
          }
        })
      } else {
        Dialog.alert({
          title: '提示',
          message: res.msg,
          showCancelButton: false,
          confirmButtonText: '确定'
        })
      }
    }
  },
  mounted:function () {   //自动触发写入的函数
    this.onCreate();
  }

触发模板为

methods: {
          demo() {
          
          }

      },
 mounted: function () {
  alert('页面一加载,就会弹出此窗口')
 }

要在fuction() 前面用async修饰、外部调用前面用await修饰,不然就会获取不到数据。

Logo

前往低代码交流专区

更多推荐