我最近与SPFx接触不多,所以我想我需要学习一下:)
我想在这里使用此NPM软件包:
https://www.npmjs.com/package/azure-search
进入基本的新SPFx Web部件:
代码如下:
export default class Azurecognitivesearchwebpart extends React.Component<IAzurecognitivesearchwebpartProps, {}> {
public render(): React.ReactElement<IAzurecognitivesearchwebpartProps> {
//var AzureSearch = require('azure-search');
var client = AzureSearch({
url: "https://x.search.windows.net",
key: "xx",
version: "2016-09-01", // optional, can be used to enable preview apis
headers: { // optional, for example to enable searchId in telemetry in logs
"x-ms-azs-return-searchid": "true",
"Access-Control-Expose-Headers": "x-ms-azs-searchid"
}
});
// search the index
client.search('azureblob-index-aihw', {search: "scott", top: 10}, function(err, results, raw){
// raw argument contains response body as described here:
// https://msdn.microsoft.com/en-gb/library/azure/dn798927.aspx
});
return (
<div className={ styles.azurecognitivesearchwebpart }>
<div className={ styles.container }>
<div className={ styles.row }>
<div className={ styles.column }>
<span className={ styles.title }>Welcome to SharePoint!</span>
<p className={ styles.subTitle }>Customize SharePoint experiences using Web Parts.</p>
<p className={ styles.description }>{escape(this.props.description)}</p>
<a href="https://aka.ms/spfx" className={ styles.button }>
<span className={ styles.label }>Learn more</span>
</a>
</div>
</div>
</div>
</div>
);
}
}
但是我收到此错误:
sp-webpart-workbench-assembly_default.js:26411 [1585151245901][OtherGlobalError.window.onerro] TypeError: Object(...) is not a function
我在这里想念什么?
和其他一些