golang wails框架初步安装配置 element plus 显示

  1. 搭建wails
wails init -n myproject -t vue
wails dev
  1. 安装element-plus
cd frontend
npm install element-plus
npm install
  1. 配置element-plus

main.js里配置如下

import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'

const app = createApp(App)

app.use(ElementPlus)
app.mount('#app')

  1. 创建1个组件
<script setup>
import {reactive} from 'vue'
import {Custom} from '../../wailsjs/go/main/App'

const myData = reactive({
  name: "",
  resultText: "Please enter your name below 👇",
})

function myHandler() {
  Custom(myData.name).then(result => {
    myData.resultText = result
  })
}
</script>


<template>
    <main>
      <div  class="result">{{ myData.resultText }}</div>
      <div class="input-box">
        <input id="name" v-model="myData.name" autocomplete="off" class="input" type="text"/>
        <button class="btn" @click="myHandler">custom</button>
      </div>
    </main>
  </template>
  1. 接入 golang对于方法

app.go 中配置

func (a *App) Custom(name string) string {
	return name + "custom text"
}

frontend\wailsjs\go\main\App.js 中增加方法

export function Custom(arg1) {
  return window['go']['main']['App']['Custom'](arg1);
}
  1. App.vue引入组件
<script setup>
import Abtn from './components/Abtn.vue'
</script>



<template>
  <Abtn/>
</template>

  1. 修改测试 frontend/src/App.vue
<script setup>
import HelloWorld from './components/HelloWorld.vue'
</script>



<template>
  <HelloWorld/>
  <el-button type="primary">Primary</el-button>
</template>

  1. 打包wails
cd ..
wails build -s

涉及资源

wails
element-plus
windows-defender-remover

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值