vue 调用c++_electron 调用原生模块及c++与js交互

环境篇

touch binding.gyp // 创建构建文件

加入以下代码

{

"targets": [

{

"target_name": "greet", // greet 为输出的文件名

"sources": [

"./src/greeting.cpp", // greeting.cpp为输入的c++文件

],

}

]

}

创建一个入口c++ 文件

cd src

touch greeting.cpp

// 放入以下代码

#include

using namespace v8;

void greetHello(const v8::FunctionCallbackInfo &args)

{

Isolate *isolate = args.GetIsolate();

Local hello = String::NewFromUtf8(isolate, "hello").ToLocalChecked();

args.GetReturnValue().Set(hello);

}

// init is entry point.

void Init(Local exports, Local module) {

NODE_SET_METHOD(exports, "greetHello", greetHello);

}

// greet 表示定义的文件名

你可能感兴趣的:(vue,调用c++)