<template>
<view class="container">
<tm-sheet></tm-sheet>
<tm-button @click='open()'>open</tm-button>
<tm-button @click='set()'>set</tm-button>
<tm-button @click='write()'>write</tm-button>
<tm-button @click='check()'>check</tm-button>
<tm-button @click='close()'>close</tm-button>
{{av}}
</view>
</template>
<script>
export default {
data() {
return {
href: 'https://uniapp.dcloud.io/component/README?id=uniui',
av:'',
}
},
methods: {
open(){
plus.sqlite.openDatabase({
name: 'first',
path: '_doc/test.db',
success:(e)=>{
console.log('openDatabase success!');
},
fail:(e)=>{
console.log('openDatabase failed: '+JSON.stringify(e));
}
});
},
set(){
plus.sqlite.executeSql({
name: 'first',
sql: 'create table citys("where" CHAR(110),"location" CHAR(100),"age" INT(11))',
success:(e)=>{
console.log('executeSql success!');
},
fail:(e)=>{
console.log('executeSql failed: '+JSON.stringify(e));
}
});
},
write(){
var d = new Date();
plus.sqlite.executeSql({
name: 'first',
sql: "insert into citys values('北京','安乐林','13')",
success:(e)=>{
console.log('executeSql success!');
},
fail:(e)=>{
console.log('executeSql failed: '+JSON.stringify(e));
}
});
},
check(){
plus.sqlite.selectSql({
name: 'first',
sql: 'select * from citys',
success:(data)=>{
console.log('selectSql success: ');
for(var i in data){
console.log(data[i]);
}
var k=data[1]['where'];
this.av=k
},
fail:(e)=>{
console.log('selectSql failed: '+JSON.stringify(e));
}
});
},
close(){
plus.sqlite.closeDatabase({
name: 'first',
success:(e)=>{
console.log('closeDatabase success!');
},
fail:(e)=>{
console.log('closeDatabase failed: '+JSON.stringify(e));
}
});
}
},
}
</script>
是一个使用JavaScript和HTML编写的代码块,该代码使用Uni-App框架创建一个移动应用程序。它包括几个与SQLite数据库交互的方法。 open()方法创建一个新的数据库,set()方法在数据库中创建一个表,write()方法向表中插入新行,check()方法选择表中的所有行并将它们记录到控制台中,close()方法关闭数据库。还有几个按钮,当点击时会触发这些方法。最后,av变量被用于存储citys表的第二行中where列的值,然后在页面上显示。